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

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

Existential Comparison

The peculiar property of these operators, namely that A = B is true if there is an item in A that is equal to an item in B, is sometimes called
existential semantics
—the operator is testing for the existence of a matching pair of items. This section explores the consequences of this rule..

Where a sequence
$N
is compared with a string
“Mary”
, the test
$N=“Mary”
is effectively a shorthand for “if there is an item
$n
in
$N
such that
$n
eq
“Mary”
”. Similarly, the test
$N!=“Mary”
is effectively a shorthand for “if there is an item
$n
in
$N
such that
$n
ne
‘Mary’
”. If
$N
contains two items, whose values are “
Mary
” and “
John
”, then
$N=‘Mary’
and
$N!=‘Mary’
will both be true, because there is an item that is equal to
‘Mary’
and another that is not. If
$N
is an empty sequence, then
$N=‘Mary’
and
$N!=‘Mary’
will both be false, because there is no item that is equal to
‘Mary’
, but there is also no item that is not equal to
‘Mary’
.

Note that when the operand is a sequence of nodes, we are only concerned with the nodes that are members of the sequence in their own right. The children of these nodes are not members of the sequence. So if
$N
is the element:


  Mary

  John


then
$N=“Mary”
will not return true. In this case $N is a singleton sequence. Its only item is the

element, and that element is not equal to
“Mary”
. In fact, with a schema-aware processor this comparison might well throw an error, on the grounds that the

node cannot be atomized. To perform an existential comparison for this example, you should write
$N/person=“Mary”
. In this expression,
$N/person
is a sequence of two

nodes, and one of them is equal to
“Mary”
.

Other books

The Gunsmith 385 by J. R. Roberts
The Age of Grief by Jane Smiley
Branded for Murder by Dick C. Waters
V - The Original Miniseries by Johnson, Kenneth
Up a Road Slowly by Irene Hunt
Husk by J. Kent Messum
Riders in the Chariot by Patrick White
Dark Melody by Christine Feehan