fn:boolean function
The fn:boolean function returns the effective boolean value of a sequence.
Syntax
- sequence-expression
- Any sequence that contains items of any type, or the empty sequence.
Returned value
The returned value is an
xs:boolean value that depends on the value of sequence-expression:
- If sequence-expression is the empty sequence, false is returned.
- If sequence-expression is not the empty sequence, and sequence-expression contains
one value:
- If the value is the xs:boolean value false, false is returned.
- If the value is a string of length 0, and the type is xs:string or xs:untypedAtomic, false is returned.
- If the value is 0, and the type is a numeric type, false is returned.
- If the value is NaN, and the type is xs:double, false is returned.
- Otherwise, true is returned.
- If sequence-expression is not the empty sequence, and sequence-expression contains more than one value, true is returned.
Examples
The
following functions return true, because they are both strings with
a length greater than zero
fn:boolean("true")fn:boolean("false")
The following function returns false, because the value
of the sequence-expression is 0 and the type is numeric: fn:boolean(0)
The
following examples show how the fn:boolean function can be used in
the larger context of Db2. The
XMLQUERY statements are used to query XML data and take an XQuery expression
as the first argument. In both cases, the fn:boolean function is passed
data from the PASSING clause. In the first example, the argument of
the fn:boolean function is a sequence of three zeros. In the second
example, the argument of the fn:boolean function is three "false"
values. Both functions evaluate to true, because the sequence-expression contains
more than one value.
XMLQUERY('fn:boolean($x)' PASSING XMLCONCAT(XMLQUERY('0'),
XMLQUERY('0'),XMLQUERY('0')))XMLQUERY('fn:boolean(fn:data(//b))'
PASSING XMLPARSE(DOCUMENT '<a><b>false</b><b>false></b><b>false</b></a>'))