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.
-
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-set, 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 examplelet $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)
. -
Maps are available (for more details see Maps. They provide a similar capability to "objects" in Javascript, or "associative arrays" in some other languages. But as befits a function language like XPath, they are immutable. A collection of functions is available to operate on maps (see ), and in addition there is new syntax for a map constructor (of the form
map{ key := value, key := value }
where both the keys and values are arbitrary expressions. There is a sequenceType for maps:map(K, V)
defining the types of the key and value parts. Maps are functions, so given a map $M, the entry for a key $K can be obtained as the result of the function call$M($K)
. -
Expanded QNames can be written in the notation
"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
, map
,
filter
, map-pairs
, pi
, sin
, cos
, tan
,
asin
, acos
, atan
, sqrt
, format-integer
, and others.
For details see .