XML technologies / XSLT / Introduction to XSLT 2.0 / XSLT and XPath – getting started / Axes and node tests / The two notations for axis specifiers
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 1.)
For the most commonly used axes, namely four element axes and the attribute axis, abbreviations of the axis specifier have become established (abbreviated syntax). Every axis also has an unabbreviated notation of its specifier (unabbreviated syntax), which can always be used.
A location step in unabbreviated notation does indeed look as shown in An axis for the direction of movement. The axis specifier is written in lowercase:
child::gruss
This is a location step along the Child axis in unabbreviated notation. It selects elements named gruss that are children of the context node.
Exactly this selection has already been described, but expressed more simply:
gruss
This is indeed an identical, complete location step, just in abbreviated notation. Since the Child axis is the most common, its axis specifier child:: is usually omitted. Thus, the Child axis is effectively the default axis for moving through the tree.
Less radical abbreviations exist for the Parent, Self, Descendant-Or-Self and attribute axes. All other axes, when needed, must be specified in unabbreviated notation.
The abbreviations for the Self and Parent axes include the neutral node test node() and thus constitute complete location steps. The abbreviation “//” represents a neutral step along the Descendant-Or-Self axis, which must be followed by another step. The other two really are abbreviations of the axis specifier itself.
Table: Abbreviations used with axes.
Expression | Abbreviation |
|---|---|
child:: | (axis specifier omitted) |
self::node() | . |
parent::node() | .. |
/descendant-or-self::node()/ | // |
attribute:: | @ |
Summary of axes and node tests
A location step in a path expression consists of an axis and a node test.
Axes describe directions of movement through the document tree. Forward and reverse axes are distinguished relative to document reading order.
Each of the thirteen axes has a particular extent in its direction, defining its primary result set.
All axes have an unabbreviated notation; some important axes also have an abbreviated notation.
The Child axis is the default axis. Its specifier is therefore usually omitted in location steps.
The node test extracts nodes with particular properties from the result set of an axis step. Tests for node kinds (KindTest) and tests for node names (NameTest) are distinguished.
Copyright © Galileo Press, Bonn 2008
You may print the online version for your private use.
Otherwise, this chapter from “XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn