Name
boolean() Function — Converts its argument to a boolean value.
Synopsis
booleanboolean(object)
Inputs
An object. The object is converted to a boolean value. This conversion is described in the following subsection.
Output
The boolean value corresponding to the input object. Objects are converted to boolean values as follows:
A number is
trueif and only if it is not zero, negative zero, orNaN(not a number).A node-set is
trueif and only if it is not empty.A string is
trueif and only if its length is greater than zero.All other datatypes are converted in a way specific to those datatypes.
Defined in
XPath section 4.3, Boolean Functions.
Example
The following example demonstrates the results of invoking the boolean() function against a variety of argument types. Here’s our XML document:
<?xml version="1.0"?> <test> <p>This is a test XML document used by several of our sample stylesheets.</p> <question> <text>When completed, the Eiffel Tower was the tallest building in the world.</text> <true>Yes! The Eiffel Tower was the world's tallest building until 1932, when New York's Empire State Building opened. </true> <false>No, the Eiffel Tower was the world's tallest building for over 30 years.</false> </question> </test>
We’ll process this document with the following stylesheet:
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:variable name="newline"> <xsl:text> </xsl:text> </xsl:variable> <xsl:template ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access