Changes

Jump to navigation Jump to search
1,110 bytes added ,  13:56, 13 July 2020
no edit summary
* <code>xs:double('NaN') * 0</code> yields <code>NaN</code> instead of <code>0</code>
* <code>true#0 and true#0</code> must raise an error; it cannot be simplified to <code>true#0</code>
 
==Paths==
 
Due to the compact syntax of XPath, it can make a big difference if a slash is added or omitted in a path expression. A classical example is the double slash {{Code|//}}, which is a shortcut for {{Code|descendant-or-node()/}}. If the query is evaluated without optimizations, all nodes of a document will be gathered, and for each of them, the next step will be evaluated. This leads to a potentially huge number of duplicate node tree traversals, most of which are redundant, as all duplicate nodes will be removed at the end anyway.
 
In most cases, paths with a double slash can be rewritten to descendant steps…
 
<syntaxhighlight lang="xquery">
doc('addressbook.xml')//city
 
(: equivalent query :)
doc('addressbook.xml')/descendant-or-node()/child::city
 
(: will be rewritten to :)
doc('addressbook.xml')/descendant::city
</syntaxhighlight>
 
…unless the last step does not contain a positional predicate:
 
<syntaxhighlight lang="xquery">
doc('addressbook.xml')//city[1]
</syntaxhighlight>
 
As the positional test refers to the city child step, a rewritten query would yield different steps.
=Changelog=
Introduced with Version 9.4.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu