fn:boolean
Computes the effective boolean value of the sequence $arg
.
Signature
fn:boolean($arg as item()*) as xs:boolean
Rules
The function computes the effective boolean value of a sequence, defined according to the following rules. See also Effective Boolean Value.
-
If
$arg
is the empty sequence,fn:boolean
returnsfalse
. -
If
$arg
is a sequence whose first item is a node,fn:boolean
returnstrue
. -
If
$arg
is a singleton value of typexs:boolean
or a derived fromxs:boolean
,fn:boolean
returns$arg
. -
If
$arg
is a singleton value of typexs:string
or a type derived fromxs:string
,xs:anyURI
or a type derived fromxs:anyURI
, orxs:untypedAtomic
,fn:boolean
returnsfalse
if the operand value has zero length; otherwise it returnstrue
. -
If
$arg
is a singleton value of any numeric type or a type derived from a numeric type,fn:boolean
returnsfalse
if the operand value isNaN
or 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].