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 effective Boolean value (EBV) depends on the value of sequence-expression:
Description of value | EBV returned |
---|---|
An empty sequence | false |
A sequence whose first item is a node | true |
A single value of type xs:boolean (or derived from xs:boolean) | false - if the xs:boolean value is false |
true - if the xs:boolean value is true | |
A single value of type xs:string or xdt:untypedAtomic (or derived from one of these types) | false - if the length of the value is zero |
true - if the length if the value is greater than zero | |
A single value of any numeric type (or derived from a numeric type) | false - if the value is NaN or is numerically equal to zero |
true - if the value is not numerically equal to zero | |
All other values | error |
Note: The effective
Boolean value of a sequence that contains at least one node and at
least one atomic value is nondeterministic in a query where the order
is unpredictable.
|
Examples
Example with an argument that
is a single numeric value: The following function returns the
effective Boolean value of 0:
fn:boolean(0)
The returned value is false.
Example with an argument that is
a multiple-item sequence: The following function returns the effective
Boolean value of (<a/>, 0, <b/>):
fn:boolean((<a/>, 0, <b/>))
The returned value is true.