-
Notifications
You must be signed in to change notification settings - Fork 0
Function Calls
Nico Kutscherauer edited this page Jun 21, 2022
·
3 revisions
This page describes how function calls, anonymous functions or high-order function calls are represented in the XPath Model.
A regular function call is represented by a function name and a list of arguments.
XPath:
concat('foo', bar, 'baz')
Model:
<function-call>
<function name="concat"/>
<arg>
<string value="foo"/>
</arg>
<arg>
<locationStep axis="child">
<nodeTest name="bar" kind="element"/>
</locationStep>
</arg>
<arg>
<string value="baz"/>
</arg>
</function-call>Anonymous functions have no names, but a parameter list. It is modeled with the element function-impl. The function body is defined by a arg element with the role='return'.
XPath:
function($foo){'(' || $foo || ')'}
Model:
<function-impl>
<param name="foo"/>
<arg role="return">
<operation type="concat">
<arg>
<string value="("/>
</arg>
<concat/>
<arg>
<varRef name="foo"/>
</arg>
<concat/>
<arg>
<string value=")"/>
</arg>
</operation>
</arg>
</function-impl>Build in functions or functions provided by the host language can be referenced by name and arity.
XPath:
concat#3
Model:
<function name="concat" arity="3"/>One aspect of the high-order function concept is, to call functions dynamically.
XPath:
$foo('arg1', 'arg2', 'arg3')
Model:
<operation type="postfix">
<arg>
<varRef name="foo"/>
</arg>
<function-call>
<arg>
<string value="arg1"/>
</arg>
<arg>
<string value="arg2"/>
</arg>
<arg>
<string value="arg3"/>
</arg>
</function-call>
</operation>