Reference: XPath syntax
This section is an informal guide to the syntax of XPath expressions, which are used in Saxon both within XSLT stylesheets, and as parameters to various Java interfaces. XPath is also a subset of XQuery. For formal specifications, see the XPath 2.0, XPath 3.0, and XPath 3.1 specifications.
This section also now contains details of new extensions in the XPath 4.0 specification, with information about the Saxon implementation. The use of these 4.0 features requires Saxon-PE or Saxon-EE, and must be enabled - for more information see Enabling 4.0 features. For an overview of the new additions see New features in XPath 4.0.
The functions provided in the XPath function library are listed separately: see the Function library section.
XPath basics
In XPath 2.0 (and higher) all values are considered as sequences. A sequence consists of zero or more items; an item may be a generic node, an atomic item or (since 3.0) a function item. (For more information about the kinds of items available, see the Types section.)
An empty sequence is written as (); a singleton sequence may be written as
"a" or ("a"), and a general sequence is written as ("a",
"b", "c").
The node-sets of XPath 1.0 are replaced in XPath 2.0 by sequences of nodes. Path expressions will return node sequences whose nodes are in document order with no duplicates, but other kinds of expression may return sequences of nodes in any order, with duplicates permitted.
XPath expressions are composed from other expressions using operators. The basic primitives of the language are the primary expressions - which include literals, variable references, context value references, function calls, and function items. For information summarizing the syntactic constructs and operators provided in XPath 2.0 and higher, see the Primary expressions and Operators sections.
Changes since XPath 2.0
This section includes summaries of New features in XPath 3.0, New features in XPath 3.1 and New features in XPath 4.0, with information about the implementation in Saxon.
An important new feature in XPath 3.1 was the definition of maps and arrays. These features are available in all current Saxon editions, whether you are using XPath, XQuery, or XSLT. A major motivation for their introduction was to support the data structures that can be defined in JSON, but they have many other uses where more complex data structures need to be built. For more details see Maps and Arrays.