2

次のような 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の値を与えます。

scoredが であるアイテムのみをカウントしたいとしますtrue。XSLT を使用してそれを行うにはどうすればよいですか? (この例では、値 2 が返されます。

4

1 に答える 1

9

次のようにします。

<xsl:variable name="scoredItems"
              select=
                  "item/attributes/scored[@value='true']"/>
于 2010-06-21T19:34:15.650 に答える