Skip to content

Commit

Permalink
Editorial changes to notes on path expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhkay committed Dec 3, 2024
1 parent 380ec50 commit 759b73b
Showing 1 changed file with 61 additions and 82 deletions.
143 changes: 61 additions & 82 deletions specifications/xquery-40/src/expressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10884,14 +10884,10 @@ return $incrementors[2](4)]]></eg>
<p>A path expression consisting of <code>/</code> on its own
is treated as an abbreviation for <code>/.</code>.</p>

<!-- An initial
<code>/</code> or <code>//</code> is an abbreviation for
one or more initial steps that are implicitly added to the
beginning of the path expression, as described below.</p>-->

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

Expand All @@ -10908,30 +10904,58 @@ return $incrementors[2](4)]]></eg>
<p>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.</p>

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

<p>Similarly, in the expression <code role="parse-test"
>/
union /*</code>, <code>union</code> is interpreted as an element name
rather than an operator. For it to be parsed as an operator,
the expression should be written <code
role="parse-test">(/)
union /*</code>.</p>

</note>


<!--is to begin the path at the root node of
the tree that contains the context node. If the context value
is not a node, a <termref
def="dt-type-error">type
error</termref> is raised <errorref class="TY" code="0020"
/>. At
evaluation time, if the root node of the context node is
not a document node, a <termref
def="dt-dynamic-error">dynamic error</termref> is
raised <errorref class="DY"
code="0050"/>.</p>-->

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

<!--<p>A <code>//</code> at the beginning of a path expression
is an abbreviation for the initial steps
<code>. ! (fn:root(self::node()) treat as
document-node())/descendant-or-self::node()/</code> </p>-->



<olist>
<item><p>A <termref def="dt-type-error"/> occurs if <var>J</var> is not a node
Expand Down Expand Up @@ -10962,19 +10986,16 @@ return $incrementors[2](4)]]></eg>
<note>
<p>The descendants of a node do not include attribute
nodes<phrase role="xpath"
> or namespace nodes</phrase>.</p>
> or namespace nodes</phrase>. However, the rules for expanding <code>//</code>
ensure that <code>.//@*</code> selects all attributes of all descendants<phrase role="xpath">,
and similarly <code>.//namespace::*</code> selects all namespaces of all descendants.</phrase></p>
</note>

<note>
<p>A <code>//</code> on its own is not allowed by the grammar.</p>
<p><code>//</code> on its own is not a valid expression.</p>
</note>

<!--<p>
A path expression that starts with <code>/</code>
or <code>//</code> selects nodes starting from the root of
the tree containing the context value; it is often referred to
as an absolute path expression.
</p>-->

</div3>

<div3 id="id-relative-path-expressions">
Expand All @@ -10993,13 +11014,12 @@ return $incrementors[2](4)]]></eg>
</p>
<p>
Each non-initial occurrence of <code>//</code> in a path expression is
expanded as described in <specref
ref="abbrev"
/>, leaving a
expanded as described in <specref ref="abbrev"/>, leaving a
sequence of steps separated by <code>/</code>. This sequence of steps
is then evaluated from left to right. So a path such as
<code>E1/E2/E3/E4</code> is evaluated
as <code>((E1/E2)/E3)/E4</code>. The semantics of a path
<code><var>E1</var>/<var>E2</var>/<var>E3</var>/<var>E4</var></code> is evaluated
as <code>((<var>E1</var>/<var>E2</var>)/<var>E3</var>)/<var>E4</var></code>.
The semantics of a path
expression are thus defined by the semantics of the
binary <code>/</code> operator, which is defined in
<specref ref="id-path-operator"/>.
Expand Down Expand Up @@ -11046,48 +11066,7 @@ return $incrementors[2](4)]]></eg>
</note>


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

<p>Similarly, in the expression <code role="parse-test"
>/
union /*</code>, <code>union</code> is interpreted as an element name
rather than an operator. For it to be parsed as an operator,
the expression should be written <code
role="parse-test">(/)
union /*</code>.</p>

</note>


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

<item>

<p>If every evaluation of <var>E2</var> returns a (possibly empty)
sequence of non-nodes, these sequences are concatenated<phrase
role="xpath">, in order,</phrase> 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 <var>E2</var>.
</p>
Expand Down

0 comments on commit 759b73b

Please sign in to comment.