MarkLogic 9 Product Documentation
fn.boolean

fn.boolean(
   arg as Sequence | Array,
   [collation as String]
) as Boolean

Summary

Computes the effective boolean value of the sequence $arg. See Section 2.4.3 Effective Boolean Value[XP].

Parameters
arg A sequence of items (as a Sequence or as an Array, where the sequence is defined as each item of the array).
collation The optional name of a valid collation URI. For information on the collation URI syntax, see the Search Developer's Guide.

Usage Notes

When using XQuery version "1.0-ml", this function implements the semantics from May 2003.

If $arg is the empty sequence, fn:boolean returns false.

If $arg is a sequence whose first item is a node, fn:boolean returns true.

If $arg is a singleton value of type xs:boolean or a derived from xs:boolean, fn:boolean returns $arg.

If $arg is a singleton value of type xs:string or a type derived from xs:string or xs:untypedAtomic, fn:boolean returns false if the operand value has zero length; otherwise it returns true.

If $arg is a singleton value of any numeric type or a type derived from a numeric type, fn:boolean returns false if the operand value is NaN or is numerically equal to zero; otherwise it returns true.

In all other cases, fn:boolean raises a type error [err:FORG0006] when run in XQuery strict mode (1.0).

The static semantics of this function are described in Section 7.2.4 The fn:boolean function[FS].

Note:

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 returns false.

Example

const x = ['a', 'b', 'c'];
fn.boolean(x);
// returns true

const x = ['a', 'b', 'c'];
fn.boolean(x[0]);
// returns true

const x = ['a', 'b', 'c'];
fn.boolean(x[4]);
// returns  false
Powered by MarkLogic Server | Terms of Use | Privacy Policy