The basic primitive for accessing a source document is the axis step. Axis steps
may be combined into path expressions using the path operators /
and //
,
and they may be filtered using filter expressions in the same way as the result of any other
expression.
An axis step has the basic form axis :: node-test
, and selects nodes on a given axis
that satisfy the node-test. The axes available are:
ancestor |
Selects ancestor nodes starting with the current node and ending with the document node |
ancestor-or-self |
Selects the current node plus all ancestor nodes |
attribute |
Selects all attributes of the current node (if it is an element) |
child |
Selects the children of the current node, in documetn order |
descendant |
Selects the children of the current node and their children, recursively (in document order) |
descendant-or-self |
Selects the current node plus all descendant nodes |
following |
Selects the nodes that follow the current node in document order, other than its descendants |
following-sibling |
Selects all subsequent child nodes of the same parent node |
namespace |
Selects all the in-scope namespaces for an element (this axis is deprecated in XPath 2.0, but Saxon continues to support it) |
parent |
Selects the parent of the current node |
preceding |
Selects the nodes that precede the current node in document order, other than its ancestors |
preceding-sibling |
Selects all preceding child nodes of the same parent node |
self |
Selects the current node |
When the child axis is used, child::
may be omitted, and when the attribute
axis is used, attribute::
may be abbviated to @
. The expression
parent::node()
may be shortened to ..
The expression .
is no longer synonymous with self::node()
,
since it may now select items that are not nodes. If the context item is not a node, any use of a
path expression will raise an error.
The node-test may be, for example:
a node name
prefix:*
to select nodes in a given namespace
*:localname
to select nodes with a given local name, regardless of namespace
text()
(to select text nodes)
node()
(to select any node)
processing-instruction()
(to select any processing instruction)
processing-instruction('literal')
to select processing instructions with the given name
(target)
comment()
to select comment nodes
element()
or element(*)
to select any element node
element(N)
to select any element node named N
element(*, T)
to select any element node whose type annotation
is T, or a subtype of T
element(N, T)
to select any element node whose name is N
and whose type annotation is T, or a subtype of T
schema-element(N)
to select any element node whose name is N,
or an element in the substitution group of N, that conforms to the schema-defined
type for a global element declaration named N in an imported schema
attribute
or attribute(*)
to select any attribute node
attrbute(N)
to select any attribute node named N
attribute(*, T)
to select any attribute node whose type annotation
is T, or a subtype of T
attribute(N, T)
to select any attribute node whose name is N
and whose type annotation is T, or a subtype of T
schema-attribute(N)
to select any attribute node whose name is N,
that conforms to the schema-defined
type for a global attribute declaration named N in an imported schema