<?xml version="1.0" encoding="UTF-8"?>
<essay xml:lang="en" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:gal="http://norman.walsh.name/rdf/gallery#">
<info>
    
    
    
    
    
    
    
    
    
    
    
    
<title>XQuery 1.0 or XSLT 2.0?</title><biblioid class="uri">http://norman.walsh.name/2004/05/19/xsltxquery</biblioid>
<volumenum>7</volumenum>
<issuenum>87</issuenum>
<pubdate>2004-05-19T08:25:00-04:00</pubdate>
<date>$Date: 2005-09-11 10:27:02 -0400 (Sun, 11 Sep 2005) $</date>
<author>
      <personname>
<firstname>Norman</firstname>
	<surname>Walsh</surname>
</personname>
    </author>
<copyright>
      <year>2004</year>
      <holder>Norman Walsh</holder>
    </copyright>
<abstract>
<para>I’ve seen a number of recent blogs about XPath 2.0, XSLT 2.0,
XQuery 1.0, and their relation to each other. My 2¢.</para>
</abstract>
<dc:subject rdf:resource="http://norman.walsh.name/knows/taxonomy#XML"/>
<dc:subject rdf:resource="http://norman.walsh.name/knows/taxonomy#XSLT"/>
</info>

<epigraph>
<attribution>
      <personname>
<firstname>Blaise</firstname>
	<surname>Pascal</surname>
</personname>
    </attribution>
<para xml:id="p1">The multitude which is not brought to act as a unity, is
confusion. That unity which has not its origin in the multitude is
tyranny.</para>
</epigraph>

<para xml:id="p2">I’ve seen a number of recent blogs about XPath 2.0, XSLT 2.0,
XQuery 1.0, and their relation to each other. Much of the current
discussion seems to have its genesis in the revelation that the next
version of .NET will have support for XQuery 1.0 and not XPath 2.0 or
XSLT 2.0. I haven’t chased down all the references to be absolutely sure
because I don’t care very much about .NET.</para>

<para xml:id="p3">Some of the reasons I’ve seen are entirely reasonable. It seems to boil
down to, “we asked the customers what they wanted and we’re giving
it to them.” Who can argue with that? But some of the reasons expressed
are misleading or just plain wrong.</para>

<para xml:id="p4"><personname>
      <firstname>Dare</firstname>
      <surname>Obasanjo</surname>
    </personname>
<link xlink:href="http://blogs.msdn.com/dareobasanjo/archive/2004/05/13/131166.aspx">argues</link>
that “XQuery is strongly and statically typed while XPath 2.0 is
weakly and dynamically typed.” What’s not clear from his post is that he is comparing
XQuery 1.0 to XPath 2.0 <emphasis>in backwards compatibility mode</emphasis>
(<personname>
      <firstname>Michael</firstname>
      <surname>Rys</surname>
    </personname>
did provide <link xlink:href="http://sqljunkies.com/WebLog/mrys/archive/2004/05/13/2479.aspx">a
clarification</link>). That’s an odd comparison to make. XPath 2.0 needs
a backwards compatibility mode so that it stands some chance of doing
the right thing when used in the context of an XSLT
<emphasis>1.0</emphasis> stylesheet, but that’s not the expected mode for long-term use.
</para>

<para xml:id="p5">XPath 2.0 and XQuery 1.0 have <emphasis>the same</emphasis> semantics,
defined by <link xlink:href="http://www.w3.org/TR/xquery-semantics/">XQuery 1.0 and XPath 2.0
Formal Semantics</link>. In fact, the
<link xlink:href="http://www.w3.org/TR/xpath20/">XPath 2.0</link> and
<link xlink:href="http://www.w3.org/TR/xquery/">XQuery 1.0</link> specifications are
generated from <emphasis>a common source document</emphasis>. They are largely
<emphasis>the same</emphasis> specification. This makes arguments about the difficulty
of implementing both XPath 2.0 and XQuery 1.0 seem a little odd, though it’s
certainly true that it’s a design choice and design choices can have a profound
impact on implementation costs.</para>

<para xml:id="p6">Some other arguments are about syntax. Yeah, there are people who will
prefer the SQL-like syntax. I’m not one of them. But
<personname>
      <firstname>Arpan</firstname>
      <surname>Desai</surname>
    </personname>
<link xlink:href="http://blogs.msdn.com/arpande/archive/2004/05/13/131408.aspx">says</link>,
within an argument about syntax,
that “the programming paradigm [of XSLT] is quite hostile to anybody
who isn't a fan of LISP.” That’s a more inflamatory tone than I would have used,
but as an argument for XQuery it seems like a non sequitur to me. They have
the same paradigm. My guess is that folks just think it’s simpler because it
doesn’t have angle brackets.</para>

<para xml:id="p7">I have built systems that rely on the fact that I can generate
XSLT with XSLT and that I can query XSLT with XSLT. I’m surprised that
the folks doing XQuery don’t see this as an important feature, but I understand
the trade-off of choosing a syntax that’s more familiar. (Yes, before someone points
it out, I’m aware that XSLT doesn’t let you query easily into XPath expressions and that
something like <link xlink:href="http://www.w3.org/TR/xqueryx/">XQueryX</link> does
allow it. I just like the 80/20 cut of XSLT a little better.)</para>

<para xml:id="p8">The funniest arguments are the ones that imply that XQuery is a
competitor in the same problem space as XSLT, that users will use
XQuery <emphasis>instead of</emphasis> XSLT. I say that’s funny because there
are so many problems that you simply <emphasis>cannot solve</emphasis> with XQuery.
If your data is regular and especially if it’s all stored in a database already
so that your XQuery implementation can run really fast, then XQuery absolutely makes
sense, but didn’t the database folks already have a query language?
Nevermind.
If your customers don’t need to solve the kinds of problems for which
XSLT was designed, or if you want to sell them some sort of
proprietary system to solve them, then implementing XSLT 2.0 probably
doesn’t make sense.
</para>

<para xml:id="p9">If you want to transform documents that aren’t regular,
especially documents that have a lot of mixed content, XSLT is clearly the
right answer. I’ll wager dinner at your favorite restaurant that XQuery cannot
be used to implement the functionality of the DocBook XSLT Stylesheets.
(You produce the XQuery that does the job, I buy you dinner.)
</para>

<para xml:id="p10">The only serious competition for XSLT 2.0 is XSLT 1.0. And it is
serious. Biting off XSLT 2.0 is going to be a non-trivial effort for
folks with significant XSLT stylesheets. My impression at the moment is that
it’s probably worth it and over time, people will migrate to 2.0 for the
additional features that it provides (grouping, regular expressions, character
maps, and standard
patterns for transforming result trees and producing multiple output documents,
for example).</para>

<para xml:id="p11">I’m certainly starting to think seriously about making the switch.</para>

</essay>

