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

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

Examples

Construct
Meaning
/
Matches a document node.
/*
Matches the outermost element node in a document (the document element). In the case of a tree that is not well formed (see page 48 in Chapter 2), it matches any element whose parent is a document node.
/booklist
Matches any

element whose parent is a document node.
//book
Matches any

element that has a document node as an ancestor.
book
Matches any

element.
element(*,
mfg:invoice)
Matches any element annotated as conforming to the schema-defined type
mfg:invoice
.
attribute(*,
xs:date)
Matches any attribute annotated as an
xs:date
, including subtypes of
xs:date
.
id(‘figure-1’)
Matches an element with an
ID
attribute having the value
‘figure-1’
.
id(‘figure-1’)//*
Matches any descendant element of an element with an
ID
attribute having the value
‘figure-1’
.
key(‘empnr’,
‘624381’) /@dob
Matches the
dob
attribute of an element having a value
‘624381’
for the key named
empnr
.

RelativePathPattern

A
RelativePathPattern
consists of a
PatternStep
defining conditions that a node must satisfy, optionally preceded by a
RelativePathPattern
that a parent or ancestor node must satisfy (the syntax puts it the other way around, but the effect is the same, and it's easier to think of it from right to left). The syntax for a
RelativePathPattern
is a subset of the syntax for a
RelativePathExpr
in the XPath Expression language.

Syntax

Expression
Syntax
RelativePathPattern
PatternStep|
PatternStep
/
RelativePathPattern |
PatternStep
//
RelativePathPattern

A
RelativePathPattern
is thus a sequence of one or more
PatternSteps
separated by either of the operators
/
(is-parent-of) or
//
(is-ancestor-of).

The syntax of a
PatternStep
is described on the next page.

Effect

Because in practice patterns are likely to be evaluated from right to left, it's easier to explain the semantics if we rearrange the syntax, as follows.

Expression
Syntax
RelativePathPattern
PatternStep | RelativePathPattern
/
PatternStep | RelativePathPattern
//
PatternStep

Other books

Tantras by Ciencin, Scott
The Trouble with Demons by Lisa Shearin
Grant Moves South by Bruce Catton
Charming, Volume 2 by Jack Heckel
Conan and the Spider God by Lyon Sprague de Camp
Blackstone (Book 2) by Honor Raconteur