Why did the point change (.) Change between XPath 1.0 and 2.0?

When you study the details of the answer to the XPath question here about stack overflow, I encounter the difference between XPath 1.0 and 2.0, I can not find any justification.

I tried to understand what it means . .

What was the reason for the change? Is there any difference between . and self::node() in XPath 2.0?

From the specification itself, the purpose of the change is not clear to me. I have tried keywords for Google such as period or period, primary expression and rationale.

+5
source share
2 answers

XPath 1.0 had four data types: string, number, boolean, and node-set. Cannot process collections of values ​​other than nodes. This meant, for example, that it was impossible to sum the derived values ​​(if the elements had attributes of the form price='$23.95' , there was no way to sum over the numbers obtained by removing the $ sign, because the result of such stripping would be a set of numbers, and this type there was no data).

So XPath 2.0 introduced more general sequences, which meant that the tools for processing sequences had to be generalized; for example, if $ X is a sequence of numbers, then $X[. > 0] $X[. > 0] filters a sequence that includes only positive numbers. But this only works if "." can refer to a number, as well as to node.

+4
source

In short: self::node() filters out atomic elements, as well . - no. Atomic elements (numbers, strings, and many other types of XML schemas) are not nodes (unlike elements, attributes, comments, etc.).

Consider the example from spec: (1 to 100)[. mod 5 eq 0] (1 to 100)[. mod 5 eq 0] . If . replaced with self::node() , the expression is not valid XPath, because mod requires both arguments to be numeric, and atomization did not help in this case.

For those who scan the specification: XPath 2.0 defines item() type construction, but this has nothing to do with node tests , since atoms are not nodes, and axis steps always return only nodes. Therefore, a point cannot be defined as self::item() . It really should be a special language construct.

+3
source

All Articles