How to use or operator in xsl: apply-templates to select an attribute?

I want to combine two expressions with the OR instruction in xsl: apply-templates select.i I want to check the following conditions ...

<xsl:apply-templates select="//w:body/w:p[w:r[w:t]] or //w:body/w:p[w:r[w:pict]]"> // My Functionality </xsl:apply-templates> 

But I do not know how to do this. Please guide me to get out of this problem ...

+2
source share
2 answers

I do not know about XSLT 2.0, but in XSLT 1.0 <xsl:apply-templates select="//w:body/w:p[w:r[w:t]] or //w:body/w:p[w:r[w:pict]]"> invalid request. Use | instead of or .

+1
source

You can use or , and it is really correct to use it in this context, because you do not need test nodes:

 <xsl:apply-templates select=" //w:body /w:p [w:r/w:t or w:r/w:pict]"> 

| (combining) is indispensable only if you need to select test nodes ( w:t and w:pict ):

 <xsl:apply-templates select=" //w:body/w:p/w:r/w:t | //w:body/w:p/w:r/w:pict"> 

where XPath 2.0 lets you write more briefly:

 <xsl:apply-templates select=" //w:body/w:p/w:r/(w:t|w:pict)"/> 
+1
source

All Articles