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

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

There is no requirement that the two nodes should be in the same document. Document order is defined as an ordering of all the nodes encountered, across all documents. If nodes are in different documents, then you can't predict which one will be first in document order, but although the answer is arbitrary, it will be consistent within a single run.

Consider again the problem given in the previous section, where the input has the form:


Another way of finding all the


elements that follow an


element identified by the variable
$H
is:

$H/following-sibling::p[not($H/following-sibling::H1[1] << .)]

This selects those


elements that are before the next


element. Note the careful construction of the predicate, which is designed to work even when
$H
does not have a
following-sibling::H1
. It works because when one of the operands of
<<
is an empty sequence, the result of the comparison is an empty sequence, which is treated as
false
. If the expression were written:

$H/following-sibling::p[$H/following-sibling::H1[1] >> .]

then it would not select any


elements after the last


element.

Changes in XPath 2.0

These three operators are new in XPath 2.0.

In XPath 1.0 the only way to test whether two variables
$A
and
$B
referred to the same node was to write something like
count($A|$B)
=
1
. This relies on the fact that the union operator
|
removes duplicate nodes. If you see this construct when upgrading existing code to XPath 2.0, using the
is
operator will almost certainly be more efficient.

In an XSLT 1.0 stylesheet, nodes could also be compared for identity using the expression
generate-id($A)
=
generate-id($B)
. Again the
is
operator is more direct and more likely to be efficient.

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

Other books

Forsaken Skies by D. Nolan Clark
The Taxman Killeth by Mitchell, Mary Ann
Two Time by Chris Knopf
The Thompson Gunner by Nick Earls
Monument 14 by Emmy Laybourne
Beyond Coincidence by Martin Plimmer
Charity Starts at Home by Zahra Owens