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
5.03Mb size Format: txt, pdf, ePub
ads

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.

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

Other books

Always a Lady by Sharon Sala
The Stranger Came by Frederic Lindsay
Deathrace by Keith Douglass
Baby Island by Brink, Carol Ryrie, Sewell, Helen
Ripples Through Time by Lincoln Cole
My Voice: A Memoir by Angie Martinez
La Reina Isabel cantaba rancheras by Hernán Rivera Letelier
The Killing Man by Mickey Spillane
The Hostage Bride by Kate Walker