fn:boolean
Computes the effective boolean value of the sequence $arg.
Signature
fn:boolean($arg as item()*) as xs:booleanRules
The function computes the effective boolean value of a sequence, defined according to the following rules. See also Effective Boolean Value.
-
If
$argis the empty sequence,fn:booleanreturnsfalse. -
If
$argis a sequence whose first item is a node,fn:booleanreturnstrue. -
If
$argis a singleton value of typexs:booleanor a derived fromxs:boolean,fn:booleanreturns$arg. -
If
$argis a singleton value of typexs:stringor a type derived fromxs:string,xs:anyURIor a type derived fromxs:anyURI, orxs:untypedAtomic,fn:booleanreturnsfalseif the operand value has zero length; otherwise it returnstrue. -
If
$argis a singleton value of any numeric type or a type derived from a numeric type,fn:booleanreturnsfalseif the operand value isNaNor is numerically equal to zero; otherwise it returnstrue.
Error Conditions
In all cases other than those listed above, fn:boolean raises a type error [ERRFORG0006].
Notes
The result of this function is not necessarily the same as $arg cast as
xs:boolean. For example, fn:boolean("false") returns the value
true whereas "false" cast as xs:boolean (which can also be
written xs:boolean("false")) returns false.
Examples
let $abc := ("a", "b", "")fn:boolean($abc) raises a type error [ERRFORG0006].
The expression fn:boolean($abc[1]) returns true().
The expression fn:boolean($abc[0]) returns false().
The expression fn:boolean($abc[3]) returns false().
fn:boolean([]) raises a type error [ERRFORG0006].