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

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
7.11Mb size Format: txt, pdf, ePub
  • Boolean operators
    and
    and
    or
    .

Many of these operators behave in a way that is likely to be familiar from other languages, though there are differences because of the different data model, in particular, the fact that everything in XPath is a sequence.

The next chapter describes the most distinctive feature of the XPath language, namely path expressions. Unlike the operators in this chapter, these are quite unique to XPath.

Looking further ahead, Chapter 10 is devoted to operations used to process sequences. The tour of the language syntax finishes in Chapter 11, which describes operations on types. Chapter 12 returns specifically to XSLT with a description of match patterns, which use a subset of the XPath syntax. The standard functions available in XPath and XSLT are described in Chapter 13.

Chapter 9

XPath: Path Expressions

This chapter defines the syntax and meaning of
path expressions
. Path expressions are the most distinctive feature of the XPath language, the construct that gives the language its name. The chapter also describes other constructs in the language that are closely associated with path expressions, in particular
steps
and
axes
and the
union
,
intersect
, and
except
operators.

Path expressions are used to select nodes in a tree, by means of a series of steps. Each step takes as its starting point a node, and from this starting point, selects other nodes.

Each step is defined in terms of:

  • An
    axis
    , which defines the relationship to be followed in the tree (for example, it can select child nodes, ancestor nodes, or attributes)
  • A
    node test
    , which defines what kind of nodes are required, and can also specify the name or schema-defined type of the nodes
  • Zero or more
    predicates
    , which provide the ability to filter the nodes according to arbitrary selection criteria

Because they are closely associated with processing the results of path expressions, this chapter also describes the operators used to combine two sets of nodes by taking their union, intersection, or difference.

Although I've chosen
Path Expressions
as the title for this chapter, the term is actually a slippery one. Because of the way W3 C defines the XPath grammar, all sorts of unlikely constructs such as
2
or
count($x)
are technically path expressions. The things I will actually cover in this chapter are:

  • The binary
    /
    operator as applied to nodes. This is used in expressions like
    $chap/title
    . There's another use of the
    /
    operator that applies to atomic values, in what I call a
    simple mapping expression
    , and I will cover that in Chapter 10.
  • Axis steps, for example
    ancestor::x
    or
    following-sibling::y[1]
    , including abbreviated axis steps such as
    x
    (short for
    child::x
    ) and
    @y
    (short for
    attribute::y
    ). Axis steps are expressions in their own right, but they are often used before or after the
    /
    operator.

Other books

A Girl in Winter by Philip Larkin
EDEN (Eden series Book 2) by Le Carre, Georgia
The Rage by Byers, Richard Lee
Aries Revealed by Carter, Mina
Princess In Denim by McKnight, Jenna
Somewhere Out There by Amy Hatvany
The Toll by Jeanette Lynn
Clementine by R. Jean Wilson