这是我的xslt。当布尔值($ y)在两者具有相同值时打印为false时,boolean($ x)打印为true的任何原因。唯一的区别是x通过调用模板获取其空字符串。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="x">
<xsl:call-template name="tmplate"></xsl:call-template>
</xsl:variable>
###x-bool:[<xsl:value-of select="boolean($x)"/>]
###x:[<xsl:value-of select="$x"/>]
<xsl:variable name="y" select="''"/>
###y-bool:[<xsl:value-of select="boolean($y)"/>]
###y:[<xsl:value-of select="$y"/>]
</xsl:template>
<xsl:template name="tmplate">
<xsl:value-of select="''"/>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:1)
唯一的区别是x通过调用a得到它的空字符串 模板。
不,这不是唯一的区别。当您将变量定义为:
时<xsl:variable name="y" select="''"/>
变量的数据类型为string
。但是当你将其定义为:
<xsl:variable name="x">
<xsl:value-of select="''"/>
</xsl:variable>
数据类型为result-tree-fragment。它包含一个包含空字符串的文本节点。因此它不是空的,并且在转换为boolean时将被计算为true()。