New features in XPath 3.0
Some of the new features in XPath 3.0 are as follows. For full details, see the W3C specifications, and for further Saxon implementation details see the Conformance section.
-
The concatenation operator
||
is available (as in SQL). For example,('$' || 12.5)
returns the string$12.5
. -
A new simple mapping operator is available,
!
. This works rather like/
, except there is no restriction that the left hand operand must be a node sequence, and there is no sorting of results into document order. For example,(1 to 7)!(.*.)
returns the sequence(1, 4, 9, 16, 25, 36, 49)
. -
Local variables can be declared in a let expression, for example
let $x := /*/@version return //e[@version = $x]
. -
Inline function items can be declared, and used as arguments to higher-order functions. For example
map(//employee, function($e){$e/salary + $e/bonus})
. A function item is a third kind of item, alongside nodes and atomic values. The function represented by a function item$f
can be invoked using a dynamic function call$f(args)
. Higher-order functions require Saxon-PE or higher. -
Expanded QNames can be written in the notation
Q{uri}local
, allowing XPath expressions to be written that do not depend on an externally-supplied namespace context.
A number of new functions are available, including head
, tail
,
for-each
, filter
, for-each-pair
, pi
,
sin
, cos
, tan
, asin
,
acos
, atan
, sqrt
, format-integer
,
and others. For details see the Functions library
section.
Maps and arrays are defined in XPath 3.1, and are available in Saxon whether you are using XPath, XSLT, or XQuery; for more details see Maps in XPath and Arrays in XPath.