use*_*808 2 xml xslt boolean xslt-2.0 xslt-1.0
我想了解的区别true()和true两者的使用。
例如:
我声明一个变量var1如下:
<xsl:variable name="var1"
select="/root/name ='' and exists(/root/name[@as:firstname])"></xsl:variable>
<!--and now I wan to use it as a condition, say:-->
<xsl:if test="$var1=true() "> <!-- Now would I use true() or true here ?-->
<xsl:text>Hello World</xsl:text>
</xsl:if>
Run Code Online (Sandbox Code Playgroud)
由于您使用布尔表达式定义了变量,因此:
<xsl:if test="$var1=true()">
Run Code Online (Sandbox Code Playgroud)
和:
<xsl:if test="$var1">
Run Code Online (Sandbox Code Playgroud)
将以同样的方式工作。不知道你的意思true; 它可能是一个节点,也可能是一个字符串“true”。在后一种情况下,测试:
<xsl:if test="$var1='true'">
Run Code Online (Sandbox Code Playgroud)
would work in XSLT 1.0 (and it would work just as well with any non-empty string), but not in XSLT 2.0.
Note also that:
string(var1)
Run Code Online (Sandbox Code Playgroud)
will return either "true" or "false", so the test:
<xsl:if test="string($var1)='true'">
Run Code Online (Sandbox Code Playgroud)
will work the way you would expect, in both XSLT 1.0 and 2.0