Skip to content

Commit

Permalink
Changes suggested by Christian in review
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhkay committed Oct 31, 2023
1 parent a5efe4c commit 2530ac7
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions specifications/xpath-functions-40/src/function-catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18748,7 +18748,7 @@ return sort($in, $SWEDISH)</eg>
<fos:function name="transitive-closure" prefix="fn">
<fos:signatures>
<fos:proto name="transitive-closure" return-type="node()*">
<fos:arg name="start" type="node()?"/>
<fos:arg name="node" type="node()?"/>
<fos:arg name="step" type="function(node()) as node()*"/>
</fos:proto>
</fos:signatures>
Expand All @@ -18763,12 +18763,12 @@ return sort($in, $SWEDISH)</eg>
</fos:summary>
<fos:rules>

<p>The value of <code>$start</code> is a node from which navigation starts. If <code>$start</code> is an
<p>The value of <code>$node</code> is a node from which navigation starts. If <code>$node</code> is an
empty sequence, the function returns an empty sequence.
</p>
<p>The value of <code>$step</code> is a function that takes a single node as input, and returns a set of nodes as its result.</p>
<p>The result of the <code>fn:transitive-closure</code> function is the set of nodes that are reachable from
<code>$start</code> by applying the <code>$step</code> function one or more times.</p>
<code>$node</code> by applying the <code>$step</code> function one or more times.</p>

<p>Although <code>$step</code> may return any sequence of nodes, the result is treated as a set: the order of nodes
in the sequence is ignored, and duplicates are ignored. The result of of the
Expand All @@ -18777,20 +18777,20 @@ return sort($in, $SWEDISH)</eg>
<p>The result of the function is equivalent to the following XQuery implementation:</p>

<eg><![CDATA[declare %private function tc-inclusive(
$start as node()*,
$step as (function(node()) as node()*)
) as node()* {
let $nextStep := $start/$step(.)
let $newNodes := $nextStep except $start
return (if (exists($newNodes))
then $start | tc-inclusive($newNodes, $step)
else $start)
$nodes as node()*,
$step as (function(node()) as node()*)
) as node()* {
let $nextStep := $nodes/$step(.)
let $newNodes := $nextStep except $nodes
return if (exists($newNodes))
then $nodes | tc-inclusive($newNodes, $step)
else $nodes
};
declare function fn:transitive-closure (
$start as node(),
$step as (function(node()) as node()*)
) as node()* {
tc-inclusive($start/$step(.)), $step)
$node as node(),
$step as (function(node()) as node()*)
) as node()* {
tc-inclusive($node/$step(.)), $step)
};]]></eg>

<note><p><emph>Explanation:</emph> The private helper function <code>tc-inclusive</code> takes a set of nodes as input,
Expand All @@ -18799,7 +18799,7 @@ declare function fn:transitive-closure (
the union of the supplied nodes and the nodes returned from the recursive
call (which will always include the new nodes selected in the first step).
If there are no new nodes, the recursion ends, returning the nodes that have been found up to this point.</p>
<p>The main function <code>tc-inclusive</code> finds the nodes that are reachable from the start node in a single
<p>The main function <code>fn:transitive-closure</code> finds the nodes that are reachable from the start node in a single
step, and then invokes the helper function <code>tc-inclusive</code> to add nodes that are reachable
in multiple steps</p></note>

Expand All @@ -18810,10 +18810,10 @@ declare function fn:transitive-closure (
the function stops searching when it finds no new nodes.</p>
<p>The function may fail to terminate if the supplied <code>$step</code> function constructs and returns
new nodes. A processor <rfc2119>may</rfc2119> detect this condition but is not required to do so.</p>
<p>The <code>$start</code> node is not included in the result, unless it is reachable by applying
the <code>$step</code> function one or more times. If a result is required that does include the <code>$start</code>
node, it can be readily added to the result using the union operator:
<code>$start | transitive-closure($start, $step)</code>.</p>
<p>The <code>$node</code> node is not included in the result, unless it is reachable by applying
the <code>$step</code> function one or more times. If a result is required that does include <code>$node</code>,
it can be readily added to the result using the union operator:
<code>$node | transitive-closure($node, $step)</code>.</p>
</fos:notes>
<fos:examples>
<fos:variable name="data" id="transitive-closure-data"><![CDATA[document{<doc>
Expand All @@ -18833,22 +18833,26 @@ declare function fn:transitive-closure (
}]]>
</fos:variable>
<fos:example>
<fos:test use="transitive-closure-data">
<fos:test use="transitive-closure-data transitive-closure-reports">
<fos:expression><eg>transitive-closure(
$data//person[@id="2"]),
$direct-reports)/string(@id)</eg></fos:expression>
$data//person[@id="2"],
$direct-reports
)/string(@id)</eg></fos:expression>
<fos:result>("3", "4", "6", "7", "8")</fos:result>
</fos:test>
<fos:test use="transitive-closure-data">
<fos:expression><eg>transitive-closure($data, function { child::* })/@id/string()</eg></fos:expression>
<fos:expression><eg>transitive-closure(
$data,
function { child::* })/@id
)/string()</eg></fos:expression>
<fos:result>("0", "1", "2", "3", "4", "5", "6", "7","8")</fos:result>
</fos:test>
</fos:example>
<fos:example>
<p>The following example, given <code>$root</code> as the root of an XSLT stylesheet module, returns the URIs
of all stylesheet modules reachable using <code>xsl:import</code> and <code>xsl:include</code> declarations:</p>
<eg>let $tc := transitive-closure(function { document(//(xsl:import|xsl:include)/@href) })
return $tc($root) =!> document-uri()</eg>
<eg>transitive-closure($root, fn { document(//(xsl:import|xsl:include)/@href) })
=!> document-uri()</eg>
<p>This example uses the XSLT-defined <code>document()</code> function.</p>
</fos:example>
</fos:examples>
Expand Down

0 comments on commit 2530ac7

Please sign in to comment.