XQuery: What you probably don't know

Do you know what XQuery is? I thought I did, but I didn't. I figured, since I had read that it was an extension of XPath, it was a more elaborate querying language. Where XPath is like the command line, XQuery would be like SQL or something like that. I was completely wrong.

XQuery is a full-on programming language meant to create XML documents. It fits the same exact spot where XSLT fits, but instead of using transforms and template-matching, XQuery is a real programming language. It's not writen *in* XML either, it looks like funky Javascript (though there is something called XQueryX which *is* valid XML and it's fugly).

I've decided that XQuery is now the *worst named XML spec ever*. I don't know how many times I blew over it because I thought I knew what it was and that I didn't need it.

There's actually some burgeoning work on some XQuery Java tools from Gnu.org and a JCP working group. A Google search will bring up a bunch of good info, but here's a good XQuery intro which goes over all the basics and more (you can define *methods* in XQuery!). Here's what XQuery looks like:

       <results>
        {
          LET $doc := document("prices.xml")
          FOR $t IN distinct($doc/book/title)
          LET $p := $doc/book[title = $t]/price
          RETURN
            <minprice title={ $t/text() }>
            { 
              min($p) 
            }
            </minprice>

        }
        </results>

Of course, you may be thinking "why in the world do we need *another* programming language?!?!" And I'm sorta with you, however, XQuery could develop into a tool that has all the advantages of XSL (offline transforms, different tools, cross platform, etc.) yet be as programatically powerful as the JSTL XML tags that I love so much.

It's a neat discovery. But please W3C: CHANGE THE NAME!!!

-Russ

< Previous         Next >