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
8.9Mb 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

Cómo mejorar su autoestima by Nathaniel Branden
The Last Full Measure by Campbell, Jack
Holiday by Stanley Middleton
His Desire by Ann King
His Mask of Retribution by Margaret McPhee
Scar Tissue by Judith Cutler
The Privateer's Revenge by Julian Stockwin