Closed MarkNicholls closed 4 months ago
This is very closely related to issue #735 (almost a duplicate). The difference is that this issue proposes the local function should be anonymous (so that the local xsl:function element is effectively an instruction that returns a function item); whereas my proposal was that the local function should be named, and added to the static context. I can see the merits in both, and the temptation is to combine them. But perhaps that would create too much complexity?
If i assign as anonymous function to local variable, isn't that a local function? (barring syntax)
If i assign as anonymous function to local variable, isn't that a local function? (barring syntax)
Not quite. Local variables aren't in scope within their own body, or within earlier instructions/declarations, so it's hard to do recursion with anonymous functions bound to variables, in the way that you can do with named functions. In addition (in 4.0) named functions have some additional capabilities such as defaulted parameter values.
ah, its not until you point it out that you realise the nuances. I'm used to functions just being values and only in scope for subsequent instructions, does that mean they effectively precede all instructions in the scope? and thus can't form closures (except from params)? Is this a problem?
Global xsl:function
declarations in XSLT are in scope throughout the stylesheet, including within their own bodies, and within other functions declared earlier. They have access to global variables, but global variables are immutable, so they don't need to go in any kind of closure.
At the F2F in Prague, group consensus was towards named, inline functions (See #735)
The CG agreed to close this issue without further action at meeting 081
I propose adding support for inline xslt functions.
Whilst XPath supports this, Xpath functions are limited in what they can do, and how "look" e.g. returning newly constructed elements isnt possible without parse-xml-fragment.
I would suggest the syntax would be basically the same as for xsl:function except with the name omitted, e.g.
benefits
alternatives