This section defines functions and operators on the xs:boolean
datatype.
Since no literals are defined in XPath to reference the constant boolean values true and false, two functions are provided for the purpose.
Function | Meaning |
---|---|
fn:true |
Returns the xs:boolean value true . |
fn:false |
Returns the xs:boolean value false . |
Returns the xs:boolean
value true
.
fn:true () as xs:boolean |
This function is ·deterministic·, ·context-independent·, and ·focus-independent·.
The result is equivalent to xs:boolean("1")
.
The expression fn:true()
returns xs:boolean(1)
.
Returns the xs:boolean
value false
.
fn:false () as xs:boolean |
This function is ·deterministic·, ·context-independent·, and ·focus-independent·.
The result is equivalent to xs:boolean("0")
.
The expression fn:false()
returns xs:boolean(0)
.
The following functions define the semantics of operators on boolean values in [XQuery 4.1: An XML Query Language] and [XML Path Language (XPath) 4.0]:
Function | Meaning |
---|---|
op:boolean-equal |
Returns true if the two arguments are the same boolean value. |
op:boolean-less-than |
Returns true if the first argument is false and the second is true. |
The ordering operator op:boolean-less-than
is provided for application purposes
and for compatibility with [XML Path Language (XPath) Version 1.0]. The [XML Schema Part 2: Datatypes Second Edition]
datatype xs:boolean
is not ordered.
Returns true
if the two arguments are the same boolean value.
Defines the semantics of the "eq"
operator when applied to two xs:boolean
values.
op:boolean-equal ( |
||
$value1 |
as xs:boolean , |
|
$value2 |
as xs:boolean |
|
) as xs:boolean |
The function returns true
if both arguments are true
or if
both arguments are false
. It returns false
if one of the
arguments is true
and the other argument is false
.
Returns true if the first argument is false and the second is true.
Defines the
semantics of the "lt" operator when applied to two xs:boolean
values. Also
used in the definition of the "ge" operator.
op:boolean-less-than ( |
||
$arg1 |
as xs:boolean , |
|
$arg2 |
as xs:boolean |
|
) as xs:boolean |
The function returns true
if $arg1
is false
and
$arg2
is true
. Otherwise, it returns
false
.
The following functions are defined on boolean values:
Function | Meaning |
---|---|
fn:boolean |
Computes the effective boolean value of the sequence $input . |
fn:not |
Returns true if the effective boolean value of $input is
false , or false if it is true . |
Computes the effective boolean value of the sequence $input
.
fn:boolean ( |
||
$input |
as item()* |
|
) as xs:boolean |
The function computes the effective boolean value of a sequence, defined according to the following rules. See also Section 2.4.3 Effective Boolean Value XP31.
If $input
is the empty sequence, fn:boolean
returns
false
.
If $input
is a sequence whose first item is a node,
fn:boolean
returns true
.
If $input
is a singleton value of type xs:boolean
or a
derived from xs:boolean
, fn:boolean
returns
$input
.
If $input
is a singleton value of type xs:string
or a type
derived from xs:string
, xs:anyURI
or a type derived from
xs:anyURI
, or xs:untypedAtomic
,
fn:boolean
returns false
if the operand value has
zero length; otherwise it returns true
.
If $input
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 cases other than those listed above, fn:boolean
raises a type error [err:FORG0006].
The result of this function is not necessarily the same as $input 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
.
let $abc := ("a", "b", "")
fn:boolean($abc)
raises a type error [err:FORG0006].
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 [err:FORG0006].
Returns true
if the effective boolean value of $input
is
false
, or false
if it is true
.
fn:not ( |
||
$input |
as item()* |
|
) as xs:boolean |
This function is ·deterministic·, ·context-independent·, and ·focus-independent·.
The value of $input
is first reduced to an effective boolean value by
applying the fn:boolean()
function. The function returns true
if the effective boolean value is false
, or false
if the
effective boolean value is true
.
The expression fn:not(fn:true())
returns false()
.
The expression fn:not(())
returns true()
.
The expression fn:not("false")
returns false()
.
fn:not(1 to 10)
raises a type error [err:FORG0006].