- From: Reece Dunn <msclrhd@googlemail.com>
- Date: Sat, 12 Dec 2020 11:33:10 +0000
- To: public-xslt-40@w3.org
- Message-ID: <CAGdtn24dAbchbhweNUVypPp9T49+ev1NJeD0ApDPN2Djzdt1CQ@mail.gmail.com>
A ·focus-dependent· function is a function that accepts the current path focus (context item `.`) as a parameter to the function. Currently this is only supported for built-in functions, but could be useful for user-defined functions. Bounded-variadic functions offer a way of doing this succinctly without any extension to the existing syntax. The logic would be: > If an argument has a default expression equal to the context item, or an expression using the context item (e.g. `./test`), the context item is evaluated at the point at which that argument is evaluated (either from a function call, or a partial function application). This would allow the Functions and Operators specification to use this to define the ·focus-dependent· functions like: fn:string($arg as item()? := .) as xs:string Note #1: I'm not restricting this to just the context item to support things like: declare function to-xsdate($year := ./year, $month := ./month, $day := ./day) {}; so the following is possible: to-xsdate(2020, 12, 10), $doc//date/to-xsdate() Note #2: I think it makes sense to have the static context bind at the function declaration, and the dynamic context bind at the call site (where the argument is passed to the parameter). Note #3: I'm not sure whether defaults that depend on parameters declared earlier should be valid or not. For example: declare function f($a, $b := $a * 2) {}; Kind regards, Reece
Received on Saturday, 12 December 2020 11:33:35 UTC