1

このような XML が与えられた場合

<data>
    <item temp="cool"/>
    <item temp="hot"/>
    <item temp="hot"/>
    <item temp="lukewarm"/>
</data>

何かがホットかどうかを簡単にテストできます。

<xsl:if test="/data/item/@temp = 'hot'">
    Something's hot in here
</xsl:if>

しかし、何もホットでないかどうかをテストするのは少し複雑です。

<xsl:choose>
    <xsl:when test="/data/item/@temp = 'hot'"></xsl:when>
    <xsl:otherwise>
        Nothing's hot in here.
    </xsl:otherwise>
</xsl:choose>

not ケースにいくつかの要素を追加したい場合がいくつかあるので、余分なコードを削除したいと思います。

とにかくこれを1つのテストステートメントに書くことができますか?

ところで、これは機能しません

<xsl:if test="/data/item/@temp != 'hot'">
    Nothing's hot in here
</xsl:if>

ひとつのものが熱くなければ過ぎてしまうからです。

4

1 に答える 1

3

これをXPathとして試してください:not(/data/item[@temp='hot'])

これは、where there does not exist an <item> that has a "temp" attribute with value "hot"

于 2013-10-22T20:39:08.803 に答える