Re: [xsl] [xslt 2.0] Local functions

Subject: Re: [xsl] [xslt 2.0] Local functions
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Thu, 19 Jul 2007 16:52:00 -0700
Having higher order functions (as provided by FXSL) eliminates the
need for local functions. One can even create functions dynamically
(by composition or by currying).


As the need for local functions has never been expressed in this list for a period of 7 years, it is logical to conclude that this topic has been created in a somewhat artificial way from a not completely XSLT standpoint of view.

It is not surprizing at all that people who are influenced by
imperative programming did sometimes ago express the need for
assignable variables. Other people now need local functions.

While it may be convenient to throw phrases like "programming in the
large", "UML", etc., it would be really interesting to see a
convincing use case for these in relation to XSLT.

--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play



On 7/19/07, Michael Kay <mike@xxxxxxxxxxxx> wrote:
> It occurs to me that it is possible to simulate local
> functions in XSLT 2.0 (which effectively could be declared
> inside xsl:template and xsl:function elements and the local
> function elements themselves).
>
> Now, given that it can be done, question is :-
>
> Would it be desirable if XSLT 2.0 were to support local functions?

Generally speaking, I think functions local to a function (or template) are
not an especially good idea. I used them in Pascal, and the net result was
some very large functions containing lots of functions which in turn
contained their own functions, and the code became very hard to read. It was
very hard to tell what was in scope at any given time. Anonymous functions
would be a different question, if we had support for higher-order functions
in the language.

Functions local to a stylesheet module - essentially private objects of any
kind - feels like a stronger candidate.

And I would love to see some way of organizing all the template rules in a
mode into some self-contained structure that keeps them tidily in one place.

For large XSLT projects (20K lines and up) the fact that everything has
global scope is certainly problematic. Disciplined use of modules and
namespaces can help, but there's still a tendency to build a rather
ramshackle structure of imports and overrides to handle different special
cases. I think modularity through pipelining is the most important weapon to
counteract this: handle special cases and variants by inserting custom
transformations into the processing pipeline rather than through overrides.
Break transformations into a sequence of simpler transformations, and
document the input and output of each through schemas. Metastylesheets
(stylesheets that generate stylesheets) can also play an important role.

Michael Kay
http://www.saxonica.com/

Current Thread