Xml xsl:if test=没有匹配的元素?
给定这样的XMLXml xsl:if test=没有匹配的元素?,xml,xslt,Xml,Xslt,给定这样的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 her
<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情况下附加一些元素,所以我想消除额外的代码
我是否可以将其写入一个测试语句
顺便说一句,这不起作用
<xsl:if test="/data/item/@temp != 'hot'">
Nothing's hot in here
</xsl:if>
这里没什么热的
因为只要有一个东西不是热的,它就会传递。尝试使用XPath:
not(/data/item[@temp='hot'])
这将转换为
,其中不存在具有值为“hot”的“temp”属性的=代码>用于比较值<代码>非()
用于节点集。