Manage Learn to apply best practices and optimize your operations.

XQuery nearly ready for prime time

In this latest XML Developer Tip, Ed Tittel takes a closer look at XQuery and why it's worth 'digging into' and learning about.

Those already familiar with XML applications know that at present XSLT (the Extensible Stylesheet Language Transformations) is the only fully standard game in town for taking XML documents as input and turning them into other forms for output, either for delivery on the Web (HTML and XHTML), transformation into other XML document types or schemas and so forth. But although the XML Query (XQuery) standard remains a working draft, recent reports from the W3C and the XML 2004 conference indicate it's sufficiently far enough along to be worth digging into and learning about.

In brief, XQuery offers a more procedural, explicit way to query XML document input, grab relevant data and operate on the results to create various forms of output, including XHTML and HTML, as well as other formats. For some applications, in fact, XQuery is emerging as a reasonable alternative to XSLT when it comes to opening documents, examining their contents and acting on the results. In fact, some experts go so far as to use the analogy that XSLT is like JavaScript and XQuery is like Java. This is their way of explaining the implicit support provided by the XSLT processor and the related data typing mechanisms that work with XSLT markup. In short, the engine that handles XQuery works with an XML Schema. It uses explicit data typing to orchestrate document interrogation, data retrieval and output handling more explicitly.

Tools like Saxon, which supports both XSLT and XQuery, and Qizx/open, which supports only XQuery, may be used to process XQuery documents that act as sets of instructions, along with command line (or shell) inputs and parameters, to select target documents on which to operate and apply specific operations against those documents. And while XSLT provides lots of implicit support and built-in operations to apply transformations on inputs to create outputs, XQuery offers (but also requires) more explicit processing controls and handling instructions.


The basis for XQuery document processing is called an FLWOR expression, which stands for:
  • For, to drive the handling of item or node sequences within an input document or stream.
  • Let, to declare and initialize variables you'll use during processing.
  • Where (optional), which permits you to specify conditions for selecting items or nodes on which to operate.
  • Order(optional), which sorts all selected nodes or items into some type of order.
  • Return, which returns a specified value (that can be the result of computation, comparison, or other transformations or selections) for each node or item selected from the input

This type of structure permits incredibly detailed, explicit and specific processing controls. Any complete FLWOR expression must include at least one For or Let element; details will vary according to the type of document interaction and outputs required. Some of the XQuery syntax derives from its specification; the rest comes from the engine that performs XQuery processing.

This application offers a more direct, explicit processing alternative to XSLT that is appealing for all kinds of applications. But it's particularly attractive -- as the name XQuery is intended to communicate -- when interacting with collections of record-structures or other well-structured data that is searched, matched, sorted and output in response to specific lookup or output needs.

In addition to the W3C references linked in the first paragraph of this tip, interested readers can learn more about XQuery from the following books:

  • Howard Katz, et al: XQuery from the Experts: A Guide to the W3C XML Query Language.
  • Michael Brundage: XQuery: The XML Query Language.
  • James McGovern, et al: XQuery Kick Start.

Of these three titles, all get strong reader and professional reviews. The McGovern title is probably the best for those not already familiar with programming using XML, but all three do a great job of covering XQuery itself.

Ed Tittel is a full-time writer and trainer whose interests include XML and development topics, along with IT certification and information security topics. E-mail Ed at etittel@techtarget.com.

Dig Deeper on Topics Archive

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchSoftwareQuality

SearchAWS

SearchCloudComputing

TheServerSide.com

Close