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

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

some $s in $S, $t in $T, $u in $U satisfies CONDITION

has exactly the same effect as the expression:

exists(for $s in $S, $t in $T, $u in $U return boolean(CONDITION)[.])

while the expression:

every $s in $S, $t in $T, $u in $U satisfies CONDITION

has exactly the same effect as the expression:

empty(for $s in $S, $t in $T, $u in $U return not(CONDITION)[.])

The rather unusual predicate
[.]
selects all the items in a sequence whose effective boolean value is true. In the first case, the result is
true
if the result of the
for
expression contains at least one value that is
true
, while in the second case, the result is
true
if the result of the
for
expression contains no value that is
false
.

(The functions
exists()
and
empty()
are described in Chapter 13. The
exists()
function returns true if the supplied sequence contains one or more items, while
empty()
returns true if the sequence contains no items.)

Examples

Expression
Description
some $i in //item satisfies
$i/price gt 200
Returns
true
if the current document contains an

element with a

child whose typed value exceeds 200.
some $n in 1 to count($S)-1 satisfies $S[$n] eq $S[$n + 1]
Returns
true
if there are two adjacent values in the input sequence
$S
that are equal.
every $p in //person satisfies $p/@dob castable as xs:date
Returns
true
if every

element in the current document has a
dob
attribute that represents a valid date, according to the XML Schema format
YYYY-MM-DD
.
some $k in //keyword,
$p in
//para satisfies contains($p,
$k)
Returns
true
if there is at least one
in the document that is present in at least one

element of the document.
every $d in //termdef/@id satisfies some $r in //termref satisfies $d eq $r/@def
Returns
true
if every

element with an
id
attribute is referenced by at least one

element with a matching
def
attribute.

Quantification and the
=
Operator

An alternative to using the
some
expression (and sometimes also the
every
expression) is to rely on the implicit semantics of the
=
operator, and other operators in the same family, when they are used to compare sequences. As we saw in Chapter 8, these operators can be used to compare two sequences, and return
true
if any pair of items (one from each sequence) satisfies the equality condition.

Other books

Safe (The Shielded Series Book 1) by Christine DePetrillo
King Hereafter by Dorothy Dunnett
Kitty's House of Horrors by Carrie Vaughn
A Shadow on the Ground by Smith, Rebecca Lee
The Alley by Eleanor Estes
In Hot Pursuit by Joanne Rock