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

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

With the first form,
PatternStep
, a node matches the pattern if it satisfies the conditions (node name, node kind, and predicates) defined in the
PatternStep
. The simplest and most common form of
PatternStep
is simply an element name, for example
title
.

With the second form,
RelativePathPattern
/
PatternStep
, a node matches the pattern if it satisfies the conditions (node name, node kind, and predicates) defined in the
PatternStep
, and if its parent node matches the
RelativePathPattern
. This
RelativePathPattern
may in turn include conditions that the parent node's parent or ancestor nodes must satisfy.

With the third form,
RelativePathPattern
//
PatternStep
, a node matches the pattern if it satisfies the conditions (node name, node kind, and predicates) defined in the
PatternStep
, and if it has an ancestor that matches the
RelativePathPattern
. This
RelativePathPattern
may in turn include conditions that the ancestor node's parent or ancestor nodes must satisfy.

Usage

Notice that although there is an equivalence between
RelativePathPattern
in the pattern language and
RelativePathExpr
in the expression language, the meaning of a
RelativePathPattern
is most easily explained by examining the
PatternSteps
from right to left, starting at the node being tested and working up through its ancestors, if necessary; this is despite the fact that the meaning of a
RelativePathExpr
is explained by considering the
Steps
from left to right, starting at the context node. It's likely that most implementations will adopt a strategy similar to the algorithm as I've explained it here.

Generally speaking, there is no point in making patterns any more selective than is necessary. For example, if a

element always appears as a child of


, then there is no point in specifying the pattern as
table/row
—you might just as well use the simpler pattern
row
.

In theory, everything you can do in a
RelativePathPattern
could be done in a single
PatternStep
, because the pattern
A/B
means exactly the same as
B[parent::A]
and the pattern
A//B
means exactly the same as
B[ancestor::A]
. However, where several steps are present, the form using
/
and
//
operators is a lot easier to read.

Other books

vnNeSsa1 by Lane Tracey
So Many Ways to Begin by Jon McGregor
Daddy's Prisoner by Lawrence, Alice, Lloyd Davies, Megan
The Last Time by E. L. Todd
Brady's Hellion by Linda Wisdom
The Sword Maker's Seal by Trevor Schmidt

© 100 Vampire Novels China Edition 2015 - 2024    Contact for me [email protected]