Name

boolean()

Converts its argument to a boolean value.

Syntax

[1.0] boolean boolean(object)
[2.0] xs:boolean boolean(item()*)

Inputs

An object. The object is converted to a boolean value. This conversion is described in the following subsection.

Output

[1.0] The boolean value corresponding to the input object. Objects are converted to boolean values as follows:

  • A number is true if and only if it is not zero, negative zero, or NaN (not a number).

  • A node-set is true if and only if it is not empty.

  • A string is true if and only if its length is greater than zero.

  • All other datatypes are converted in a way specific to those datatypes.

[2.0] For XSLT 2.0, things are more complicated. The value returned, as you’d expect, is an xs:boolean. Here’s how the argument to boolean() is converted to a boolean value:

  • If the argument is a singleton of any numeric type, boolean() returns false if the value is zero or NaN (not a number); everything else returns true.

  • If the argument is a singleton of type xs:string, xs:anyURI, xs:untypedAtomic, or any type derived from them, boolean() returns true if the argument has a length greater than zero.

  • If the argument is a singleton of type xs:boolean (or of a type derived from xs:boolean), boolean() simply returns the argument as is.

  • If the argument is a sequence whose first item is a node, boolean() returns true.

  • If the argument is the empty sequence, boolean() returns false.

  • If the argument is anything else (xs:date, xs:time, or a sequence of multiple atomic values, for ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.