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

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.

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

Other books

Mr Golightly's Holiday by Salley Vickers
A Bar Tender Tale by Melanie Tushmore
Alibi in High Heels by Gemma Halliday
Gat Heat by Richard S. Prather
WolfsMate_JCS by Desconhecido(a)
The Vanishings by Jerry B. Jenkins, Tim LaHaye
The Revenge of Excalibur by Sahara Foley