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

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

Effect

So what exactly does the
/
operator do?

I will explain this in terms of an expression
E1/E2
, where
E1
and
E2
are arbitrary expressions. This expression is evaluated as follows:

  • E1
    is evaluated to produce a sequence of nodes; let's call this
    S1
    . If the result of
    E1
    contains an atomic value, a type error is reported.
  • For each node in
    S1
    , the expression
    E2
    is evaluated. The context for evaluating
    E2
    has this node from
    S1
    as the context node. It also has the position of this node in the sequence
    S1
    as the context position, and the number of nodes in
    S1
    as the context size, but in practice it's very rare to write an expression on the right-hand side of
    /
    that depends on the context position or size.
  • Each time
    E2
    is evaluated, it produces a sequence which must either consist entirely of nodes, or entirely of atomic values (if it doesn't, a type error is reported). For the moment, we're only interested in the case where it delivers nodes; the other case is described in Chapter 10 (page 644). All the nodes produced when
    E2
    has been evaluated once for every node in
    S1
    are bundled together into a single sequence. Duplicate nodes are then removed, and the remaining nodes are sorted into document order.
  • The resulting sequence of nodes forms the result of the path expression
    E1/E2
    .

The most common kind of expression to use on the right hand side of
/
is an
axis step
. We'll describe axis steps in detail later in this chapter, on page 606. The syntax also allows a
FilterExpr
, which in effect means any expression, except that if it contains operators that bind less tightly than
/
(an obvious example is
|
) then it must be written in parentheses.

Other books

The Seventh Seal by Thorn, J.
Violins of Autumn by Amy McAuley
A Long Way from Home by Alice Walsh
The Friendship Doll by Kirby Larson
Gaudete by Ted Hughes
Claws of the Cat by Susan Spann
The Dark Side by M. J. Scott
A Shade of Dragon 3 by Forrest, Bella