XPath 2.0 implementation
Sequences of nodes or simple values are supported,
including the sequence constructor expression ($a, $b, $c)
.
Path expressions now return a sequence of nodes containing no duplicates, in document
order.
The new if expressions, for expressions, some and every expressions are supported.
New operators are implemented: except, intersect and union for combining sequences (implemented only for sequences of nodes at this release); also ==, !== for comparing node identity, and << and >> for comparing relative position of nodes in document order. These return () when an operand is (), and fail when an operand contains more than one node.
Any expression may now appear on the right-hand side of the "/" operator (a run-time error
is reported if it doesn't evaluate to a sequence of nodes). Examples: a/(b|c)/d
,
or document('x')/key('a','b')
Added range expressions. For example 1 to 10
evaluates to the
sequence ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 )
The new numeric data types integer, decimal, and float are implemented. XPath literals, and string-to-number conversion, now allow "e" in a numeric literal. A literal containing an "e" is interpreted as a double, any other literal containing a "." is interpreted as a decimal, and any other numeric literal as an integer. Integers are limited to 64-bit quantities, but decimals are of unlimited size. Arithmetic is now done using the XPath 2.0 type promotion rules, except that "div" and "mod" always convert both arguments to double. For the time being, I have retained the XPath 1.0 rule that the string representation of a number never ends in ".0"; I found that changing it to use the canonical representation defined in XML Schema (as required by XPath 2.0) meant rewriting too many of my tests. However, negative zero now converts to the string "-0" (it was "0" at XPath 1.0).
The code for equals, not-equals, etc, has been generalized to work on any sequence in the same way as for a node-set. This retains the "existential" semantics of XPath 1.0. It still does a comparison of the string-value of each item, not the typed value.
Filter expressions now work on any sequence (including a singleton sequence, so 2[1] is allowed)
3-valued logic has been implemented for AND and OR. (This doesn't reflect the XPath 2.0 working draft as published: a late change was made).
The syntax *:localname
(like prefix:*) is allowed in path expressions, and also
in patterns and in xsl:strip-space
and xsl:preserve-space
. It matches
any node with the given local name, regardless of namespace.
The Context object has been changed so that there is a context item rather than a context node. The context item is either a simple value or a node. The expression "." returns the value of the context item. If the context item is not a node, then relative path expression (including self::node()) return an empty node-set. Absolute path expressions (starting with "/"), and key() and id(), now apply to the document containing the current node, as distinct from the context node. Note: the implementation of context document doesn't accurately reflect the concept of the context document in the XPath 2.0 working draft as published.
The rules for string-to-boolean conversion have changed so that "", "0" and "false" now return false, all other strings return true.