Skip to content

Commit

Permalink
Add specification for fn:op() (issue qt4cg#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhkay committed Oct 18, 2022
1 parent c24cec3 commit b7aec53
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
59 changes: 59 additions & 0 deletions specifications/xpath-functions-40/src/function-catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16853,6 +16853,65 @@ return fn:sort($in, $SWEDISH)
</fos:example>
</fos:examples>
</fos:function>

<fos:function name="op" prefix="fn">
<fos:signatures>
<fos:proto name="op" return-type="function(item()*, item()*) as item()*">
<fos:arg name="operator" type="xs:string"/>
</fos:proto>
</fos:signatures>
<fos:properties>
<fos:property>deterministic</fos:property>
<fos:property>context-independent</fos:property>
<fos:property>focus-independent</fos:property>
<fos:property>higher-order</fos:property>
</fos:properties>
<fos:summary>
<p>Returns a function whose effect is to apply a supplied binary operator to two arguments.</p>
</fos:summary>
<fos:rules>
<p>The supplied operator must be one of the following:</p>
<p><code><![CDATA[",", "and", "or",
"+", "-", "", "div", "idiv", "mod",
"=", "<", "<=", ">", ">=", "!=",
"eq", "lt", "le", "gt", "ge", "ne",
"<<", ">>", "is", "||", "|",
"union", "except", "intersect", "to",
"otherwise"]]></code></p>
<p>The result of calling <code>fn:op("⊙")</code>, where <code>⊙</code> is one of the above operators, is
the function represented by the XPath expression:</p>
<p><code>function($x, $y) { $x ⊙ $y }</code></p>
<p>For example, <code>op("+")</code> returns <code>function($x, $y) { $x + $y }</code>.</p>
</fos:rules>
<fos:errors>
<p>A dynamic error is raised if the supplied argument is not one of the supported operators ([TODO: error code]).
</p>
</fos:errors>
<fos:notes>
<p>The function is useful in contexts where an arity-2 callback function needs to be supplied, and
a standard operator meets the requirement.</p>
<p>For example, the XSLT <code>xsl:map</code> instruction
has an <code>on-duplicates</code> attribute that expects such a function. Specifying
<code>on-duplicates="op(',')"</code> is equivalent to specifying
<code>on-duplicates="function($x, $y) { $x, $y }</code></p>
<p>The function is also useful in cases where the choice of operator to apply is
made dynamically.</p>
</fos:notes>
<fos:examples>
<fos:example>
<fos:test>
<fos:expression>fn:for-each-pair(21 to 25, 1 to 5, fn:op("+"))</fos:expression>
<fos:result>22, 24, 26, 28, 30</fos:result>
</fos:test>
</fos:example>
<fos:example>
<fos:test>
<fos:expression>fn:for-each-pair(21 to 25, 1 to 5, fn:op("-"))</fos:expression>
<fos:result>20, 20, 20, 20, 20</fos:result>
</fos:test>
</fos:example>
</fos:examples>
</fos:function>

<fos:function name="same-key" prefix="op">
<fos:signatures>
Expand Down
6 changes: 5 additions & 1 deletion specifications/xpath-functions-40/src/xpath-functions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5928,14 +5928,18 @@ correctly in all browsers, depending on the system configuration.</emph></p>-->
</div2>
<div2 id="dynamic-loading">
<head>Dynamic Loading</head>
<p>The following functions allow dynamic loading and execution of XQuery queries and XSLT stylesheets.</p>
<p>The following functions allow dynamic loading and execution of XQuery queries and XSLT stylesheets,
or XPath operators.</p>
<?local-function-index?>
<div3 id="func-load-xquery-module">
<head><?function fn:load-xquery-module?></head>
</div3>
<div3 id="func-transform">
<head><?function fn:transform?></head>
</div3>
<div3 id="func-op">
<head><?function fn:op?></head>
</div3>
</div2>
</div1>

Expand Down

0 comments on commit b7aec53

Please sign in to comment.