【问题标题】:XPath multiple conditions on same child node同一个子节点上的 XPath 多个条件
【发布时间】:2016-11-16 13:48:39
【问题描述】:

我需要根据其中一个孩子是否满足所有条件来过滤节点。这是一个例子:

<root>
    <grp pos="1">
        <test pos="1" id="2"/>
        <test pos="2" id="1"/>
        <test pos="3" id="1"/>
        <test pos="4" id="2"/>
        <test pos="5" id="1"/>
    </grp>
    <grp pos="2">
        <test pos="6" id="1"/>
        <test pos="7" id="2"/>
        <test pos="8" id="1"/>
        <test pos="9" id="1"/>
        <test pos="10" id="2"/>
    </grp>
</root>

和xsl

<xsl:template match="/root">
    <xsl:value-of select="grp[test/@pos='1' and test/@id='1']/@pos"/>
</xsl:template>

我需要test 来为这两种情况引用同一个节点。我想要的是没有任何grp 节点来传递条件,但第一个节点可以,因为它有一个通过第一个条件的子节点和另一个通过第二个条件的子节点。我希望谓词需要一个同时通过的孩子。

【问题讨论】:

    标签: xml xslt xpath


    【解决方案1】:

    好的,我不知道,但您似乎可以嵌套谓词:

    &lt;xsl:value-of select="grp[test[@pos='1' and @id='1']]/@pos"/&gt;

    这就是我想要的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多