uses node-sets as arguments for boolean() function : 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="/">
      <TABLE border="1">
        <TR>
          <td>node-set</TH>
          <td>boolean</TH>
        </TR>
        <TR>
          <TD>
            <xsl:text>/</xsl:text>
          </TD>
          <TD>
            <xsl:value-of select="boolean(/)"/>
          </TD>
        </TR>
        <TR>
          <TD>
            <xsl:text>//text</xsl:text>
          </TD>
          <TD>
            <xsl:value-of select="boolean(//text)"/>
          </TD>
        </TR>
        <TR>
          <TD>
            <xsl:text>//number</xsl:text>
          </TD>
          <TD>
            <xsl:value-of select="boolean(//number)"/>
          </TD>
        </TR>
        <TR>
          <TD>
            <xsl:text>//text[23]</xsl:text>
          </TD>
          <TD>
            <xsl:value-of select="boolean(//text[23])"/>
          </TD>
        </TR>
      </TABLE>
    </xsl:template>
</xsl:stylesheet>

Output:

<?xml version="1.0" encoding="UTF-8"?><TABLE border="1"><TR><td>node-set</TH><td>boolean</TH></TR><TR><TD>/</TD><TD>true</TD></TR><TR><TD>//text</TD><TD>true</TD></TR><TR><TD>//number</TD><TD>false</TD></TR><TR><TD>//text[23]</TD><TD>false</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