Discussions

News: XQuery Primer written from Michael Kay

  1. XQuery Primer written from Michael Kay (5 messages)

    Michael Key, author of Saxon and a series of books on XSL, has written a quick tutorial on XQuery for Stylus Studio called "Learn XQuery in 10 Minutes." The introduction says it's "for all those people who really want to know what XQuery is, but don't have the time to find out."

    It walks through a fairly simple, but common, type of document, where it's selecting a film based on references to actors. It starts off with an XPath example, culminating with this:
    //video[actorRef=//actors/actor[ends-with(., 'Lisa')]/@id]/title
    It ends up with a far more suitable (and powerful) XQuery statement:
    declare variable $firstName external;
    <videos featuring="{$firstName}">
    {
       let $doc := .
       for $v in $doc//video,
          $a in $doc//actors/actor
       where ends-with($a, 'Lisa')
          and $v/actorRef = $a/@id
       order by $v/year
       return
          <video year="{$v/year}">
             {$v/title}
          </video>
    }
    </videos>
    Finally, the article closes with a discussion of using XQuery with databases.
    If you've got a real database, however, the form of the queries won't need to change all that much from these examples. Instead of using the doc() function (or simply ".") to select a document, you're likely to call the collection() function to open a database, or a specific collection of documents within a database. The actual way collections are named is likely to vary from one database system to another. The result of the XQuery collection() function is a set of documents (more strictly, a sequence of documents, but the order is unlikely to matter), and you can process this using path expressions or FLWOR expressions in just the same way as you address a single document.
    XQuery is seen as a core part of the XML toolbox because of its much clearer syntax as compared to XPath, even though it uses XPath as a basis. (For example, the article shows exact equivalency between an XPath query and an XQuery query, with XPath as the expression and XQuery as a language construct, with some XPath-isms embedded.)

    What do you think?

    Threaded Messages (5)

  2. What do you think?[ Go to top ]

    What do you think?

    I generally think positive in life.
  3. If XQuery wasn't so cryptic, it could become the "one query language to rule them all".

    A Data Model and Algebra for XML Query
    Relational Algebra: Mother Tongue—XQuery: Fluent

    Regards,
    Henrique Stekcleberg
  4. lose the $$$$ing $s[ Go to top ]

    Cryptic? Not exactly. It has to be read carefully, but as far as I am concerned the main reason WHY it has to be read so carefully is the [many, very bitter expletives deleted] dollar signs. There is a limit to how much respect I can have for any language that looks like a late-1980's modem script. $Why $hasn't $the $entire $profession $risen $up $in $furious $revolt $against $this $syntactic $monstrosity?
  5. XQuery Primer written from Michael Kay[ Go to top ]

    What do you think?

    I develop with XML/XSLT rarely, but when I do I find it extremely useful. However, when I do use it I find I need to re-learn a lot of it each time because the terminology is (for me) so complex. What could be presented in a simple manner as a rich declarative language with a tag-based syntax is split into these sections - XSL (or is it XSLT?) XQuery, XPath, XPointer. Every time I deal with this I find it confusing.

    When I use Java, I just use Java. I don't use Java + JProcedure + JObject + JNamespaces + ... (Well, OK, there are things like annotations and generics, but these are part of the main language).

    I am probably misunderstanding some key points, but I just don't see why it all has to be so split up and obscure.
  6. I think if you reformat the XPath expression a bit it seems to me to be a lot more concise and readable than that big procedure written in XQuery.


    Pat