请原谅我缺乏XSLT的经验。
这是我的XSL样本:我正在寻找一种替代方案来实现XSL
<xsl:when test="/can/be/a/very/long/location/path/@value > 0 ">
<xsl:value-of select="/can/be/a/very/long/location/path/@value" />
</xsl:when>
这似乎是<value-of select="...">
可以更简洁。
这怎么可能呢?
请原谅我缺乏XSLT的经验。
这是我的XSL样本:我正在寻找一种替代方案来实现XSL
<xsl:when test="/can/be/a/very/long/location/path/@value > 0 ">
<xsl:value-of select="/can/be/a/very/long/location/path/@value" />
</xsl:when>
这似乎是<value-of select="...">
可以更简洁。
这怎么可能呢?
对于这个特殊的例子,你可以简单地写:
<xsl:value-of select="/can/be/a/very/long/location/path/@value[. > 0]" />
如果没有值选择
这也可以做这样的 -
<xsl:variable name="location" select="/can/be/a/very/long/location/path/@value"/>
<xsl:if test="$location">
<xsl:value-of select="$location" />
</xsl:if>
<xsl:when>
当你有多个条件,这样做的正确方法大多采用的是
<xsl:choose>
<xsl:when test="condition1"> </xsl:when>
<xsl:when test="condition2"> </xsl:when>
<xsl:when test="condition3"> </xsl:when>
<xsl:otherwise> </xsl:otherwise>
</xsl:choose>
感谢
你可以简单地使用带谓词的<xsl:template>
执行此任务:
<xsl:template match="/can/be/a/very/long/location/path[@value > 0]">
<xsl:value-of select="@value" /> <!-- current axis is 'path' -->
</xsl:template>
不错,输出什么,什么时期在这种情况下,是什么意思? – Rod
它指的是上下文项。方括号内的谓词就像一个函数,它应用于选定序列中的每个项目以返回true或false,并且“。”是函数的参数,也就是被测试的项目。 –