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

Michael Kay mike at saxonica.com
Wed Nov 7 19:12:38 PST 2007


> > I there a reason behind your preference or is it just a personal 
> > preference?  I've always considered XSLT's XML syntax to be an 
> > advantage when you're adding XML to the result...
> 
> Or course it's just personal preference, but I think it's a 
> preference shared by the majority of programmers in the world 
> - otherwise people would be writing their Java or C++ in XML.
> 

There are three main benefits that XSLT users get from its XML-based syntax:

(a) you can move incrementally from authoring to programming. Start by
writing the XHTML, then take out some of the constants and replace them with
expressions that calculate the value. There are an awful lot of people who
have taken this route, and it's often said that non-programmers find it
easier to learn XSLT than programmers do, for this reason.

(b) you're integrated into the XML environment, you can take advantage of
all the XML-based tooling that's out there. For example, it tends to be
easier to store stylesheets in an XML database than to store queries. You
can embed schemas in stylesheets, stylesheets in XProc, and so on:
everything fits together.

(c) you get reflection/introspection for free. Most XSLT-based applications
of any kind of scale end up taking advantage of the ability of stylesheets
to process other stylesheets. I can't write a query that processes queries -
not easily, anyway.

There are also a couple of less obvious advantages:

(d) it's easier for the language designers to develop and grow the syntax
and make it extensible, while maintaining stylistic consistency

(e) it's easier to write processors that produce good compile-time
diagnostics - that's an inevitable consequence of having more redundancy
(=verbosity) in the language

Having said that, there's no doubt that there are many tasks where XQuery
requires fewer keystrokes. But on the whole my experience is that Saxon
users who start off liking XQuery for its conciseness tend to find
themselves writing more and more XSLT as the application gets bigger. That's
not all due to the XML syntax of course - it's probably more because of the
dynamic template despatch and import precedence, as well as goodies like
grouping, analyze-string, format-date and the rest.

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



More information about the talk mailing list