The primitive type xs:boolean
represents a logical true
or false
value. The valid lexical representations for xs:boolean
are false
, true
, 0
(which is equal to false
), and 1
(which is equal to true
). The values are case-sensitive, so TRUE
and FALSE
are not valid lexical representations.
In addition to the standard xs:boolean
constructor, xs:boolean
values can be constructed using the true
and false
functions, which take no arguments and return the appropriate value. For example, true( )
returns the value true
.
Boolean values are more often constructed indirectly, as:
The result of a function that returns a Boolean value, such as exists($seq1)
The value of a comparison expression, such as $price > 20
The result of a path expression that is evaluated using its effective Boolean value, such as if (doc("catalog.xml")//product) ...
In addition, a function named boolean
can be used to explicitly convert a sequence to its effective Boolean value. A sequence that is an xs:boolean
value false
, a single number 0
or NaN
, a single zero-length string, or the empty sequence, evaluates to false
. Otherwise, it evaluates to true
. Note that it doesn't give the same result as the xs:boolean
constructor—for example, xs:boolean("false")
is false, but boolean("false")
is true. More information on the boolean
function can be found in Appendix A.
Values of type xs:string
or xs:untypedAtomic
can be cast to xs:boolean
. The string false
(all lowercase), or the string 0
is converted to the value false
. The string true
(all lowercase) or 1
is converted to true
. Any other string value raises an error; other strings that may appear to be equal to 0 or 1, such as 0.0
or 01
, are not accepted.
Values of any of the numeric types can also be cast to and from xs:boolean
. A numeric value that is equal to 0 or NaN
is converted to false
; any other numeric value is converted to true
.
Likewise, values of type xs:boolean
can be cast to xs:string
, xs:untypedAtomic
, and any of the numeric types. When they are cast to xs:string
or xs:untypedAtomic
, they are represented as true
and false
, not their numeric equivalents.
18.118.253.198