[xquery-talk] replacing a node in in-memory XML

Michael Kay mike at saxonica.com
Fri Nov 9 12:10:37 PST 2007

> Most programmers gave up on self modifying code a long time 
> ago - so I can never understand XSLT user's fascination with 
> this. Surely it is only indicative of a language that isn't 
> powerful enough in the first place - maybe first class 
> functions would solve this?

Possibly, I don't know. The most recent example I saw was the stylesheets
used to format the XML Rec itself, where the version of the stylesheet that
produces XHTML was produced by transforming the version that was written to
produce HTML. I think the language is powerful enough to allow the code to
be written in a way that is parameterized so one stylesheet can do both
jobs; but the approach that was used here is probably easier and gives fewer
maintenance problems. I've seen similar techniques used to handle input
variations, for example RSS input that is in a namespace or in no namespace.
The alternative solution in both these cases (and the approach that would be
used with XQuery) is probably a pipeline that involves preprocessing or
postprocessing to change the namespace.

There are a few things in XSLT that notoriously can't be parameterized, for
example the expression used to compute a sort key, and this accounts for
many cases of stylesheet modification. XQuery tends to be even less
parameterizable in these areas. Higher order functions would definitely help
in these situations. However, if we look at the SQL analogy, I think that
run-time construction of SQL statements is seen in very many applications
(hence all the fuss about code injection).

Michael Kay

More information about the talk mailing list