Rabbit blowing horn Work the Web

Lotus XSLT-based XML Query (Experimental)

Document Author: Scott Boag
Document Date: June 30, 1999
Software Version: 0.18.0 [30-August-1999]

1. Introduction

Warning: I expect this document may be a little out of date...

The XML Query architecture of LotusXSL is composed of four parts:

  1. An xml framework for interfacing to XML parsers and DOM implementations.
  2. An implementation of an XPath engine.
  3. A driver interface for various data access, for various XML and non-XML data access.
  4. An implementation of an XSLT engine.

An XPath expression searches a rooted tree of nodes beginning from a given context, and returns a node-set (a list of nodes in document order).

An XSLT stylesheet, or transformation specification, specifies the transformation of a class of XML documents by describing how an instance of the class is transformed into another XML tree of nodes.

The main idea is that a query can done one of three ways:

a) Just using XPath (xpath.bat, com.lotus.xpath.Process). In this case, it's a question as to what to do with the output. On the command line right now, I just output some silly-looking XSL. It's clear that a URI syntax needs to be developed that lets you specify both the xpath query itself, and the stylesheet transformation that should be used to deliver the nodeset.

b) Use xpath from the command in combination with a small default or specified transformation for each of the nodes (xq.bat, com.lotus.xsl.XQuery).

c) Using a full XSLT stylesheet. In this case the stylesheet is started with an empty DOM, and the XPath queries are done from the stylesheet (xslt.bat, com.lotus.xsl.Process).

Note that according to the upcoming XSLT specification, transformation specs can now be specified as simple templates, without the xsl:stylesheet, xsl:transform, or xsl:template wrappers, though the features are limited when used in this way. All that is required is to put the xslt namespace declaration on the root element.

In order to make queries work beyond a single file work, there is a files:connect() function, which returns a node set of parsed documents, which can then be used with predicates and the like to do repository queries over multiple documents. files:connect() takes a directory specification and a crude filter string that matches the end of the string. For instance:
xq -select "files:query('samples', '.xml')[//a]"
will locate all documents in the samples directory whose names terminate with '.xml', and that have a 'a' element somewhere in them.

xq -select "query('samples', '.xml')/doc/a[@test='true']"
will locate all 'a' elements that have a 'test' attribute that has a value of 'true'.

The files:connect function is a special extension. First, when using XQuery, the extension is automatically registered with the "dom" prefix. Second, the extension returns an XLocator object. When this xpath implementation has an extension that returns an XLocator object, it then calls the locationPath(XPath xpath, Node context, int opPos, Vector connectArgs method on it, passing in the same args which were passed to connect (or whatever it's called) in the vector, which allows the XLocator to process from the given LocationPath context.

Note that a connect function, for a given implementation, can have multiple arguments. Also note that it's result can be assigned to a variable in XSLT transforms.

You can override the default transformation of xq, by using the -transform switch and specifying an XSLT stylesheet. The default transformation is a simple identity transformation of the located nodes and their attributes if they have any, but not of their children. The default transformation is:

<?xml version='1.0'?>
<xq:copy xmlns:xq='http://www.w3.org/XSL/Transform/1.0'>
  <xq:for-each select='@*'>
    <xq:copy/>
  </xq:for-each>
</xq:copy>

Thanks goes to Ashok Malhotra, Virinder Batra, Christina Lau, David Fallside, Ned Batchelder, Paul Cotton, Sanjiva Weerawarana, David Marston, Noah Mendelsohn, Dean Burson, Joseph Kesselman, Pat O'Connor, Mike Pogue, Paul Dick, Adam Peller, David Bertoni, the XSL WG, and others!


2. Samples

  1. xq -in "samples/accp02.xml" -select "//title/text()"
  2. xq -in "samples/accp02.xml" -select "//titleStmt/title/text()"
  3. xq -in "samples/accp02.xml" -select "//titleStmt/title/text()" -transform trans1.xqt

3. API

See the JavaDoc for XQuery, for the simple interface. (Lots more to be written for this section).


4. Contact Info and Bug Reports

  1. Contact information for myself: Scott Boag

5. Glossary

XSLT Instruction
Any tag with an XSL namespace prefix.
XSLT Template Instruction
Any tag with an XSL namespace prefix that occurs inside an xsl:template element.
Template Child
Any node that is a child of an xsl:template element.
Source Tree
The tree input to the XSL process.
Result Tree
The tree that is output by the XSL process.
Stylesheet Tree
The stylesheet tree produced from the XSL file.
Transformation Spec
An XSLT stylesheet used for transformation purposes.