|
> <xsl:apply-templates select="document('products.xml')//product[@id = current()/@ref]">
The XSLT 2.0 draft spec 6.2 says "The xsl:apply-templates instruction takes as input a sequence of nodes in the source tree". One could argue that prohibits your usage, since the nodes aren't in the "source tree". But I think it's
just a poor choice - I agree it *should* be allowed.
The main advantage of XQuery is that everything
nests. You can iterate over one of more
data-sets (i.e. a join), construct elements
containg arbirary expressions based on each
value of the "loop", and pass arbitary data
as arguments and results of user-defined functions. I don't offhand know if there is
a set of XQuery programs you can't express
in XSLT, but think many of them will be a lot
more natural and compact using XQuery.
For now we'll just have to disagree, at least
until there is more experience with XQuery, or
I read a good analysis of their relative "power".
>The big difference is how easy it is to *create*
>> XML nodes using XQuery, and then process them
>> just like nodes from an input document.
>> With e.g. JSP you create *text*, not *nodes*.
> I suppose I can see that. Offhand, I can't think of an example of where this would be important to
> me, but maybe I just don't have the right kind of application in mind.
Think of filters, where you're passing data from
one transformation to another. If the data are
nodes rather than text, not only can you express
a transformation chain very compactly and
naturally as a set of function calls, but it
also should be more efficient than continuously
formatting and parsing the data.
> I'm still eager to see some examples that show how XQuery can solve the same problem better than
> XSLT. Can you point me to something like this? I really am interested in the possibility of
> applying XQuery in my own work, but haven't found the compelling reason to use it over XSLT.
Well, perhaps for you, who are fluent in XSLT,it's not that compelling. But I'd be curious to see
how you'd the photo album application. See
http://xml.com/pub/a/2002/12/23/xquery.html
- the latest version version of the XQuery source is
http://www.gnu.org/software/qexo/qalbum/pictures.xql
and an example showing most of the features is
http://pics.bothner.com/2002/BristleconePines/ .)
|