xsl-list
[Top] [All Lists]

RE: [xsl] [xslt 2.0] Local functions

2007-07-19 15:27:36
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/


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>