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

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

selects the attribute node whose name is
isbn
and whose parent node is the context node. So assuming that each

element actually has an
isbn
attribute, the final result contains three attribute nodes, one for each of the three books. In this case there won't be any duplicate nodes to get rid of, and the final result will be the sequence of three attribute nodes in document order.

As we've already noted, in XPath 2.0
/
is a regular operator in the sense that there are no syntactic restrictions on its operands, but it is a little unusual because it evaluates the expression on the right repeatedly. Operators and functions that work like this are often called higher-order operators, and if you've used functional programming languages before, you will recognize
/
as behaving like a
map
or
apply
operator in such languages; it maps the sequence that's the result of the first expression by applying the second expression to each item in that sequence.

Another interesting thing about the
/
operator is that there's very little point using an expression on the right-hand side if its result doesn't depend in some way on the context node. However, there is no rule that enforces this as a constraint. You can write an expression such as
$N/$M
if you like, as long as
$N
is a sequence of nodes. If you follow through the rules given above, you'll see that the result contains all the nodes in
$M
, in document order, except in the case where
$N
is empty, in which case the final result is empty. During the design stage, some reviewers wanted to disallow such expressions. But on the whole, it's not a good principle in language design to disallow things just because they aren't useful. On that basis, you would stop people writing
$X+0
, or
$X*1
. There's even a case that makes sense:
./$M
selects all the nodes in
$M
, in document order and with duplicates removed.

Other books

Tiana (Starkis Family #3) by Cheryl Douglas
The Force Awakens (Star Wars) by Alan Dean Foster
All Hallows' Eve by M.J. Trow
The Sigma Protocol by Robert Ludlum
(2013) Shooter by Jack Parker
Dead Girl Dancing by Linda Joy Singleton
Foxfire by Barbara Campbell
The Murdock's Law by Loren D. Estleman
Searching for Grace Kelly by Michael Callahan