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.
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 email@example.com.