GNOME Bugzilla – Bug 363002
boolean() of empty string sometimes returns true instead of false
Last modified: 2006-11-18 13:09:03 UTC
Please describe the problem: When $foo is a string variable, and $foo is equal to the empty string, then boolean($foo) is supposed to return false. Sometimes, it is returning true instead. Steps to reproduce: Run the following stylesheet on itself with xsltproc: $ cat > bug.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output encoding="ISO-8859-1" method="text"/> <xsl:template match="/*"> <xsl:variable name="foo"> <xsl:value-of select="''"/> </xsl:variable> <xsl:choose> <xsl:when test="boolean($foo)">boolean($foo) is true </xsl:when> <xsl:otherwise>boolean($foo) is false </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> ^D $ xsltproc bug.xsl bug.xsl boolean($foo) is true $ Actual results: boolean($foo) is true Expected results: boolean($foo) is false Does this happen every time? yes Other information: System is SuSE 10. RPM is libxslt-1.1.14-3.
The xpath boolean() function in libxslt (actually part of libxml2) is behaving correctly. The two xsl declarations <xsl:variable name = "foo" select = "''"/> and <xsl:variable name = "foo"> <xsl:value-of select = "''"/> </xsl:variable> are **NOT** equivalent. The first of these gives a string, and boolean($foo) will return false, since it's string length is zero. The second of these gives a "result tree fragment", which is treated as a node-set (see http://www.w3.org/TR/xslt#variable-values). Since the node-set is not empty (it contains a text node with an empty string), the result of boolean($foo) is true.