how to use or statement in xsl:apply-templates sel

2019-07-11 05:06发布

问题:

I want to match two expression using OR statement in xsl:apply-templates select.i want to check 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 dont know how i do this. Please Guide me to get out of this issue...

回答1:

I don't 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]]"> isn't valid query. Use | instead of or.



回答2:

You can use or, and it's really correct to use it in this context because you don't want the testing nodes:

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

| (union) is indispensabile only if you need to select the testing 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 allows you to write more concisely:

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


标签: xml xpath xslt