Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
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 |
//book | Matches any |
book | Matches any |
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 |