xslt - 计算 XSLT 中具有某些属性值的节点

标签 xslt select variables value-of

假设我有这样的 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。

最佳答案

这样做:

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

关于xslt - 计算 XSLT 中具有某些属性值的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3087748/

相关文章:

C++ I/O 多路复用服务器过早关闭连接

PHP:将变量传递给函数,对变量执行某些操作,然后将其返回

javascript - 基于分配给它的特定 css 类的另一个 div #id 隐藏带有 css #id 的 div

select - Go select 语句解决方法中的优先级

python - 通过局部空间中的函数更改局部空间中的值

XSLT 忽略命名空间

xml - 如何使用 xslt 在特定 xml 上运行 xpath

xslt - BizTalk 将名称值对映射到分层架构

xml - XSL-FO 外部图形未显示

mysql - 如何在不丢失所有行的情况下获得特定列的总和?