This article includes a
list of references,
related reading, or
external links, but its sources remain unclear because it lacks
inline citations. (December 2022) |
XPath 3 is the latest version of the XML Path Language, a query language for selecting nodes in XML documents. It supersedes XPath 1.0 and XPath 2.0.
XPath 3.0 became a W3C Recommendation on 8 April 2014, while XPath 3.1 became a W3C Recommendation on 21 March 2017.
Compared to XPath 2.0, XPath 3.0 adds the following new features:
function($a as xs:double, $b as xs:double) as xs:double { $a * $b }
creates a function that returns the product of its two arguments. The expression collection()/(let $a := . return function() { $a })
creates a sequence of functions, each one returning a different node from a collection.$f2("Hi there")
fetches the second item from sequence $f
, and invokes it as a function, passing the string "Hi there"
as argument.math:pi
may be expanded to Q{http://www.w3.org/2005/xpath-functions/math}pi
, embedding the namespace URI inside the prefix.||
operator may be used for
string concatenation: $a || $b
is equivalent to fn:concat($a, $b)
.!
operator performs simple mapping: E1 ! E2
evaluates E2
for each item in the sequence E1
, and concatenates the resulting items. This is comparable to the path operator /
, but the !
operator does not perform duplicate elimination nor document ordering of the results.XPath 3.1 mainly adds support for array and map ( associative array) data types. These types and their associated functionality are intended to ease working with JSON data.
Another innovation is the arrow operator =>
for function chaining. For example, the XPath 2.0 expression
contains(upper-case(substring-before($in, ' ')), 'X')
can now be written
$in => substring-before(' ') => upper-case() => contains('X')
This article includes a
list of references,
related reading, or
external links, but its sources remain unclear because it lacks
inline citations. (December 2022) |
XPath 3 is the latest version of the XML Path Language, a query language for selecting nodes in XML documents. It supersedes XPath 1.0 and XPath 2.0.
XPath 3.0 became a W3C Recommendation on 8 April 2014, while XPath 3.1 became a W3C Recommendation on 21 March 2017.
Compared to XPath 2.0, XPath 3.0 adds the following new features:
function($a as xs:double, $b as xs:double) as xs:double { $a * $b }
creates a function that returns the product of its two arguments. The expression collection()/(let $a := . return function() { $a })
creates a sequence of functions, each one returning a different node from a collection.$f2("Hi there")
fetches the second item from sequence $f
, and invokes it as a function, passing the string "Hi there"
as argument.math:pi
may be expanded to Q{http://www.w3.org/2005/xpath-functions/math}pi
, embedding the namespace URI inside the prefix.||
operator may be used for
string concatenation: $a || $b
is equivalent to fn:concat($a, $b)
.!
operator performs simple mapping: E1 ! E2
evaluates E2
for each item in the sequence E1
, and concatenates the resulting items. This is comparable to the path operator /
, but the !
operator does not perform duplicate elimination nor document ordering of the results.XPath 3.1 mainly adds support for array and map ( associative array) data types. These types and their associated functionality are intended to ease working with JSON data.
Another innovation is the arrow operator =>
for function chaining. For example, the XPath 2.0 expression
contains(upper-case(substring-before($in, ' ')), 'X')
can now be written
$in => substring-before(' ') => upper-case() => contains('X')