compares "0" as a string and as a number : Boolean Functions  « XSLT stylesheet « XML Tutorial






File: Data.xml
<?xml version="1.0" encoding="utf-8"?>
<data>
    <text>999</text>
    <text>A123</text>
    <text>-16</text>
    <text>0</text>
    <text/>
    <text>false</text>
</data>

File: Transform.xslt

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="/">
      <paragraph>
        <xsl:text>The boolean value of "0" is </xsl:text>
        <B>
          <xsl:value-of select="boolean(//text[text()='0'])"/>
        </B>
        <xsl:text> if "0" is a string, but </xsl:text>
        <B>
          <xsl:value-of select="boolean(number((//text[text()='0'])))"/>
        </B>
        <xsl:text> if "0" is a number.</xsl:text>
      </P>
    </xsl:template>
</xsl:stylesheet>

Output:

<?xml version="1.0" encoding="UTF-8"?><paragraph>The boolean value of "0" is <B>true</B> if "0" is a string, but <B>false</B> if "0" is a number.</P>








5.38.Boolean Functions
5.38.1.Boolean Functions
5.38.2.Use strings as arguments of boolean() function.
5.38.3.compares "0" as a string and as a number
5.38.4.uses node-sets as arguments for boolean() function
5.38.5.The not function returns true if its argument is false, and false otherwise.
5.38.6.Functions true() and false() are useful, when some conditions are tested during programming