当被告知返回false时,模板返回true()

Rad*_*row 1 xml xslt xpath

为什么我从该模板作为返回值成为真:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:template name="return-false">
		<xsl:value-of select="false()"/>
	</xsl:template>
	<xsl:template match="/">
		<root>
			<xsl:variable name="call-template">
				<xsl:call-template name="return-false"/>
			</xsl:variable>
			<xsl:if test="$call-template = true()">
				<FALSE/>
			</xsl:if>
		</root>
	</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
猜猜我在输出文档FALSE元素上得到了什么。我想知道我应该哭还是应该为在这个简单例子上的奋斗而笑。我的挫败感冲天而起。

mic*_*57k 5

xsl:value-of指令创建一个文本节点。

<xsl:value-of select="false()"/>
Run Code Online (Sandbox Code Playgroud)

返回字符串值的的false()功能,这是字符串“假”。因此,$call-template变量的内容是一个包含字符串“ false”的文本节点。

http://www.w3.org/TR/xslt/#value-of

接下来,测试test="$call-template = true()"返回true(),因为:

  • 您正在将文本节点与布尔值进行比较;
  • 首先将与布尔值比较的节点转换为布尔值;
  • true()转换为布尔值时,将评估存在的节点。

http://www.w3.org/TR/xpath/#booleans