XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (314 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
6.32Mb size Format: txt, pdf, ePub

Note that the effective boolean value of a sequence doesn't simply test whether the sequence is empty, because of the special cases for a singleton sequence. If you want to test whether a sequence is empty, use the
empty()
or
exists()
functions described in Chapter 13.

These rules for forming the effective boolean value are consistent with the rules used in other XPath contexts where a true/false value is required. These include:

  • The operands of
    and
    and
    or
    (see Chapter 8)
  • The argument of the functions
    boolean()
    and
    not()
    (see Chapter 13)
  • The expression used as a predicate within square brackets in an axis step or filter expression, so long as the value is not numeric (see Chapters 9 and 10)
  • The expression in the
    satisfies
    clause of
    some
    and
    every
    expressions (see Chapter 10)

The same rules are also used in XSLT 2.0, in evaluating the

and

instructions.

A significant feature of these rules is that the processor can determine the effective boolean value of any sequence without looking further than the second item in the sequence. This makes the algorithm very efficient.

However, the rules are not the same as the rules in XML Schema for converting a string to an
xs:boolean
value. In XML Schema, the valid lexical representations of the
xs:boolean
value
false
are
0
and
false
, while the valid lexical representations of
true
are
1
and
true
. The XML Schema rules are used in XPath 2.0 in the following circumstances:

Other books

Fermentation by Angelica J.
Hanging Hill by Mo Hayder
The Book of One Hundred Truths by Julie Schumacher
Dark Justice by Jack Higgins
Catch by Michelle D. Argyle
Listen to the Mockingbird by Penny Rudolph
City of Hawks by Gary Gygax
Poisoned Pearls by Leah Cutter