【问题标题】:Counting nodes with certain attribute values in XSLT在 XSLT 中计算具有某些属性值的节点
【发布时间】:2010-06-21 19:20:07
【问题描述】:

假设我有一些这样的 XML:

    <section name="SampleSection">
        <item name="ScoredItem1">
            <attributes>
                <scored data_type="boolean" value="true"/>
            </attributes>
        </item>
        <item name="UnscoredItem1">
            <attributes>
                <scored data_type="boolean" value="false"/>
            </attributes>
        </item>
        <item key="(3272fbb5:22)" name="ScoredItem2">
            <attributes>
                <scored data_type="boolean" value="true"/>
            </attributes>
        </item>
    </section>

现在,我知道,使用 XSLT,我可以像这样计算具有 scored attribute 的项目:

<xsl:variable name="scoredItems" select="item/attributes/scored"/>
<xsl:value-of select="count($scoredItems)"/>

当然,这会给我一个 3 的值。

假设我只想计算scoredtrue 的那些项目。我如何使用 XSLT 做到这一点? (对于本示例,这应该返回值 2。

【问题讨论】:

    标签: xslt select variables value-of


    【解决方案1】:

    这样做:

    <xsl:variable name="scoredItems"
                  select=
                      "item/attributes/scored[@value='true']"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-08
      • 2018-06-26
      • 2013-11-30
      • 2013-06-06
      • 1970-01-01
      • 2011-07-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多