XPath Expression 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.

New Features in XPath 3.0 and 3.1

There are summaries of New Features in XPath 3.0 (originally published as XPath 2.1) and New Features in XPath 3.1, and information about the implementation in Saxon.

An important new feature in XPath 3.1 is the definition of maps. This feature is in fact included in the XPath 3.0 implementation in Saxon (and thus was available as an advanced feature since Saxon 9.5, before the full implementation of XPath 3.1 in Saxon 9.7). For more details see Maps in XPath.

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 node or an atomic value, or in 3.0 it may also be a function item. Examples of atomic values are integers, strings, booleans, and dates. A single value such as a number is considered as a sequence of length 1. The 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 syntax

The functions provided in the XPath function library are listed separately: see the Function Library section. This section summarizes the following syntactic constructs and operators provided in XPath 2.0 and higher: