Use strings as arguments of boolean() function. : Boolean Functions  « XSLT stylesheet « XML Tutorial






A string is true if and only if its length is non-zero. 


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="/">
      <TABLE border="1">
        <TR>
          <td>text</TH>
          <td>boolean</TH>
        </TR>
        <xsl:for-each select="//text">
          <TR>
            <TD>
              <xsl:value-of select="."/>
              <xsl:text/>
            </TD>
            <TD>
              <xsl:value-of select="boolean(text())"/>
            </TD>
          </TR>
        </xsl:for-each>
      </TABLE>
    </xsl:template>
</xsl:stylesheet>

<?xml version="1.0" encoding="UTF-8"?><TABLE border="1"><TR>
<td>text</TH><td>boolean</TH></TR><TR><TD>999</TD><TD>true</TD>
</TR><TR><TD>A123</TD><TD>true</TD></TR><TR><TD>-16</TD><TD>true
</TD></TR><TR><TD>0</TD><TD>true</TD></TR><TR><TD/><TD>false</TD>
</TR><TR><TD>false</TD><TD>true</TD></TR></TABLE>








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