From 759b73be8891ed9bacbd6ae96da36ed5b30d52a6 Mon Sep 17 00:00:00 2001 From: Michael Kay Date: Sun, 1 Dec 2024 11:41:57 +0000 Subject: [PATCH] Editorial changes to notes on path expressions --- specifications/xquery-40/src/expressions.xml | 143 ++++++++----------- 1 file changed, 61 insertions(+), 82 deletions(-) diff --git a/specifications/xquery-40/src/expressions.xml b/specifications/xquery-40/src/expressions.xml index 39094d390..576030a17 100644 --- a/specifications/xquery-40/src/expressions.xml +++ b/specifications/xquery-40/src/expressions.xml @@ -10884,14 +10884,10 @@ return $incrementors[2](4)]]>

A path expression consisting of / on its own is treated as an abbreviation for /..

- -

An expression of the form /PP (that is, a path expression +

An expression of the form /PP (that is, a path expression with a leading /) is treated as an abbreviation for - the expression self::node()/(fn:root(.) treat as document-node())/PP. + the expression self::node()/(fn:root(.) treat as document-node())/PP. The effect of this expansion is that for every item J in the context value V:

@@ -10908,30 +10904,58 @@ return $incrementors[2](4)]]>

The results of these multiple evaluations are then combined into a single sequence; if the result is a set of nodes, the nodes are delivered in document order with duplicates eliminated.

+ + +

The / character + can be used either as a complete path expression or as the + beginning of a longer path expression such as + /*. Also, * + is both the multiply operator and a wildcard in path + expressions. This can cause parsing difficulties when + / appears on the left-hand side of + *. This is resolved using the leading-lone-slash + constraint. For example, /* and / + * are valid path expressions containing wildcards, + but /*5 and / * 5 raise syntax + errors. Parentheses must be used when / is + used on the left-hand side of an operator that could be confused with a node test, as in (/) * 5. Similarly, 4 + / * + 5 raises a syntax error, but 4 + (/) * 5 is a valid expression. + The expression 4 + / is also + valid, because / does not occur on the left-hand + side of the operator.

+ +

Similarly, in the expression / + union /*, union is interpreted as an element name + rather than an operator. For it to be parsed as an operator, + the expression should be written (/) + union /*.

+ +
+ - -

An expression of the form //PP (that is, a path expression +

An expression of the form //PP (that is, a path expression with a leading //) is treated as an abbreviation for - the expression self::node()/(fn:root(.) treat as document-node())/descendant-or-self:node()/PP. + the expression self::node()/(fn:root(.) treat as document-node())/descendant-or-self:node()/PP. The effect of this expansion is that for every item J in the context value V:

- - +

A occurs if J is not a node @@ -10962,19 +10986,16 @@ return $incrementors[2](4)]]>

The descendants of a node do not include attribute nodes or namespace nodes.

+ > or namespace nodes. However, the rules for expanding // + ensure that .//@* selects all attributes of all descendants, + and similarly .//namespace::* selects all namespaces of all descendants.

-

A // on its own is not allowed by the grammar.

+

// on its own is not a valid expression.

- + @@ -10993,13 +11014,12 @@ return $incrementors[2](4)]]>

Each non-initial occurrence of // in a path expression is - expanded as described in , leaving a + expanded as described in , leaving a sequence of steps separated by /. This sequence of steps is then evaluated from left to right. So a path such as - E1/E2/E3/E4 is evaluated - as ((E1/E2)/E3)/E4. The semantics of a path + E1/E2/E3/E4 is evaluated + as ((E1/E2)/E3)/E4. + The semantics of a path expression are thus defined by the semantics of the binary / operator, which is defined in . @@ -11046,48 +11066,7 @@ return $incrementors[2](4)]]> - -

The / character - can be used either as a complete path expression or as the - beginning of a longer path expression such as - /*. Also, * - is both the multiply operator and a wildcard in path - expressions. This can cause parsing difficulties when - / appears on the left-hand side of - *. This is resolved using the leading-lone-slash - constraint. For example, /* and / - * are valid path expressions containing wildcards, - but /*5 and / * 5 raise syntax - errors. Parentheses must be used when / is - used on the left-hand side of an operator that could be confused with a node test, as in (/) * 5. Similarly, 4 + / * - 5 raises a syntax error, but 4 + (/) * 5 is a valid expression. - The expression 4 + / is also - valid, because / does not occur on the left-hand - side of the operator.

- -

Similarly, in the expression / - union /*, union is interpreted as an element name - rather than an operator. For it to be parsed as an operator, - the expression should be written (/) - union /*.

- - - +
Path operator (/) @@ -11103,7 +11082,7 @@ return $incrementors[2](4)]]> code="0019" />. Each node in S then serves in turn to provide an inner focus (the node as the context value, its position in S as the context - position, the length of S as the context size) for an evaluation + position, the length of S as the context size) for an evaluation of E2, as described in . The sequences resulting from all the evaluations of E2 @@ -11120,9 +11099,9 @@ return $incrementors[2](4)]]>
+

If every evaluation of E2 returns a (possibly empty) - sequence of non-nodes, these sequences are concatenated, in order, and returned. + sequence of non-nodes, these sequences are concatenated, in order, and returned. The returned sequence preserves the orderings within and among the subsequences generated by the evaluations of E2.