Generating XPath reports from XML instances

$Date: 2006/12/04 15:12:17 $(UTC)


Table of Contents

1. Introduction
2. Text report - Crane-xml2xpath.xsl
3. HTML report - Crane-xml2xpath-html.xsl
3.1. Browser viewing of an XPath report
4. Instance report - Crane-xml2xpath-instance.xsl
Bibliography

1. Introduction

During the development of UBL 1.0, the Forms Presentation Subcommittee (FPSC, now renamed the Human Interface Subcommittee, or HISC) innovated the concept of an "XPath file" for the UBL document models.

XPath reports turn out to be very useful not only for document models, but also for XML instances. By dealing with the XPath report only for a given instance, one isn't distracted by the enumeration of all possible information items when only the information items at hand are of interest.

These are XSLT 1.0 stylesheets and example invocations shown are for Saxon 6.5.5 [Saxon].

2.  Text report - Crane-xml2xpath.xsl

The Crane-xml2xpath.xsl stylesheet is invoked by an XSLT processor to produce a text result. An example invocation by Saxon is as follows:

saxon -o test.txt test.xml Crane-xml2xpath.xsl

3.  HTML report - Crane-xml2xpath-html.xsl

The Crane-xml2xpath-html.xsl stylesheet is invoked by an XSLT processor to produce an HTML result. An example invocation by Saxon is as follows:

saxon -o test.htm test.xml Crane-xml2xpath-html.xsl

3.1.  Browser viewing of an XPath report

Using stylesheet association [Assoc] and an XSLT-enabled web browser, it is possible to render an XPath report directly from the instance for which a report is needed.

With both the xml2xpath-html.xsl and xml2xpath.xsl stylesheet in the same directory as the XML instance, a stylesheet association processing instruction can be added to the instance, at the top of the file (but after the XML declaration if it is present) as follows:

<?xml-stylesheet type="text/xsl" href="Crane-xml2xpath-html.xsl"?>

Of course the href= can be changed to a relative or absolute URL to point to these stylesheets found in any other directory.

4.  Instance report - Crane-xml2xpath-instance.xsl

The Crane-xml2xpath-instance.xsl stylesheet is invoked by an XSLT processor to produce an XPath instance result having the identical structure as the input but with the content replaced by XPath reference numbers. An example invocation by Saxon is as follows:

saxon -o testout.xml test.xml Crane-xml2xpath-instance.xsl

Bibliography

[Saxon] Michael Kay Saxon