Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XPath Reference

boolean Function

Converts the argument to a Boolean.

boolean boolean(arg)

Remarks

This function converts arguments to Booleans according to the following rules.

Example

XML File

None; the XSLT file calls itself.

If you use the sample XML file, books.xml, and change the href attribute to reference bool.xsl, boolean(//book) resolves as true.

XSLT File (bool.xsl)

<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="bool.xsl"?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>

<xsl:template match="/">
    <html>
       <body>
          <h3>boolean() Function</h3>
          
          <ul>
             <li><b>boolean(0)</b> = 
                <xsl:value-of select="boolean(0)"/>
             </li>
             <li><b>boolean(1)</b> = 
                <xsl:value-of select="boolean(1)"/>
             </li>
             <li><b>boolean(-100)</b> = 
                <xsl:value-of select="boolean(-100)"/>
             </li>
             <li><b>boolean(100)</b> = 
                <xsl:value-of select="boolean(100)"/>
             </li>
             <li><b>boolean(NaN)</b> = 
                <xsl:value-of select="boolean(NaN)"/>
             </li>
             <li><b>boolean('hello')</b> = 
                <xsl:value-of select="boolean('hello')"/>
             </li>
             <li><b>boolean('')</b> = 
                <xsl:value-of select="boolean('')"/>
             </li>
             <li><b>boolean(//book)</b> = 
                <xsl:value-of select="boolean(//book)"/>
             </li>
             <li><b>boolean(//notfound)</b> = 
                <xsl:value-of select="boolean(//notfound)"/>
             </li>
          </ul>
       </body>
    </html>
</xsl:template>

</xsl:stylesheet>

Formatted Output

boolean() Function

Processor Output

<html>
<body>
<h3>boolean() Function</h3>
<ul>
<li><b>boolean(0)</b> = 
      false</li>
<li><b>boolean(1)</b> = 
      true</li>
<li><b>boolean(-100)</b> = 
      true</li>
<li><b>boolean(100)</b> = 
      true</li>
<li><b>boolean(NaN)</b> = 
      false</li>
<li><b>boolean('hello')</b> = 
      true</li>
<li><b>boolean('')</b> = 
      false</li>
<li><b>boolean(//book)</b> = 
      true</li>
<li><b>boolean(//notfound)</b> = 
      false</li>
</ul>
</body>
</html>

See Also

Data Types in Schemas | XDR Schema Data Types Reference | XML Data Types Reference | NaN Values | Sample XML File (books.xml)