Re: ACTION-2309: Research xpath3 function definitions

All,

IIRC, this was about whether we can use XPath 3 function definitions if any
to replace the proposed XForms 2.0 ones.

The XPath 3.1 spec [1] says:

    "XPath per se does not provide a way to declare named functions, but a
host language may provide such a mechanism."

On the other hand, XQuery 3.1 says: [2]

    "In addition to the built-in functions, XQuery allows users to declare
functions of their own."

This includes:

    "User defined functions are functions that contain a function body"

The syntax looks like this (example from the spec):

    declare function local:depth($e as node()) as xs:integer
    {
        if (fn:empty($e/*)) then 1
        else fn:max(for $c in $e/* return local:depth($c)) + 1
    };

The body of the function consists simply of an XQuery expression with
the function parameters as in-scope variables, as one would expect.

With the current XForms 2.0 spec, [3] this would look like:

    <function signature="local:depth($e as node()) as xs:integer">
        if (fn:empty($e/*)) then 1
        else fn:max(for $c in $e/* return local:depth($c)) + 1
    </function>

In addition, XForms 2.0 supports the `<xf:var>` and `<xf:result>` elements.
The reason is that it "allows writing more readable custom functions with
XPath 1.0 and XPath 2.0, which do not natively support variables".

If we were going for the XQuery 3.1 syntax, we would still need to specify
where to place these functions, presumably with an enclosing element such
as `<functions>` or similar.

I tend to think that we would not benefit that much from using the XQuery
syntax but we can discuss the details during our call.

-Erik

[1] https://www.w3.org/TR/xpath-31/
[2] https://www.w3.org/TR/xquery-31/#FunctionDeclns
[3]
https://www.w3.org/community/xformsusers/wiki/XForms_2.0#The_function_Element

On Fri, Dec 10, 2021 at 7:14 AM XForms Users Community Group Issue Tracker <
sysbot+tracker@w3.org> wrote:

> ACTION-2309: Research xpath3 function definitions
>
> https://www.w3.org/2005/06/tracker/xforms/actions/2309
>
> Assigned to: Erik Bruchez
>
>
>
>
>
>
>
>
>

Received on Friday, 21 January 2022 03:45:49 UTC