SAXONICA |
This document is an informal guide to the syntax of XPath 2.0 expressions, which are used in Saxon both within XSLT stylesheets, and in the Java API. For formal specifications, see the XPath 2.0 specification, except where differences are noted here.
XPath expressions may be used either in an XSLT stylesheet, or as a parameter to various Java
interfaces. The syntax is the same in both cases. In the Java interface, expressions are handled
using the net.sf.saxon.xpath.XPathEvaluator
class, and are parsed using a call such as
XPathEvaluator.createExpression("$a + $b")
.
This returns an object of class net.sf.saxon.xpath.XPathExpression
,
which provides two methods for evaluating the expression: evaluate()
, which returns the value
of the expression, and iterator()
, which allows iteration over the items in the sequence
returned by the expression. For further details of these methods, see the API documentation.
An important change in XPath 2.0 is that all values are now considered as sequences. A sequence
consists of zero or more items; an item may be a node or a simple-value. Examples of simple-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.
This section summarizes the syntactic constructs and operators provided in XPath 2.0. The functions provided in the function library are listed separately: see the Functions section.