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

2019-07-11 05:32发布

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...

标签: xml xpath xslt
2条回答
叼着烟拽天下
2楼-- · 2019-07-11 05:36

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)"/>
查看更多
在下西门庆
3楼-- · 2019-07-11 05:57

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.

查看更多
登录 后发表回答