XML Convert 2.2
Invoking XML Convert from SAXON
This page describes how to invoke XML Convert from SAXON, which is Michael Kay's XSLT processor.
NOTE: XML Convert does not include SAXON. You can download SAXON for free at http://saxon.sourceforge.net/.
We'll examine the following scenarios in which SAXON can invoke XML Convert:
SAXON can invoke XML Convert, in order to read a flat file as the source document. Thus, SAXON can use the XML Convert flat file parser to transform a non-XML source document into XML, HTML or text.
At the command line, SAXON allows you to specify a SAX2 driver for parsing the source document. The full class name of this SAX2 driver is specified as the value of SAXON's -x flag. The com.unidex.xflat.Sax2FlatFileParser class is a SAX2 driver for the XML Convert flat file parser. If you invoke SAXON with this class name as the value of the -x flag, then SAXON will use the Sax2FlatFileParser class to parse the source document (which will be a non-XML flat file).
In the following command, we invoke SAXON from the command line, in order to transform a flat file (i.e., data.txt) into an XML document (i.e., data.xml) using an XSLT stylesheet (i.e., data.xsl). The command, which is quite long, is displayed as multiple lines for readability. However, when invoking this command at the command prompt, you should enter it as a single line.
java -Dcom.unidex.xflat.schema-file-name=data.xfl -Dcom.unidex.xflat.suppress-startup-message=true com.icl.saxon.StyleSheet -o data.xml -x com.unidex.xflat.Sax2FlatFileParser data.txt data.xsl
Note that the name of the XFlat schema file (i.e., data.xfl) and the value for the suppress-startup-message flag (i.e., true) are specified on the command line via the following system properties:
For more information about these system properties, please see the javadoc for the com.unidex.xflat.Sax2FlatFileParser class.
The command above is equivalent to the following two commands, in which the flat2xml application writes the XML output to a temporary file (i.e., tmp.xml), which SAXON then transforms into the data.xml file.
java flat2xml -s data.xfl data.txt tmp.xml java com.icl.saxon.StyleSheet -o data.xml tmp.xml data.xsl
The following sections of the Examples page further illustrate how to invoke SAXON, such that it uses the Sax2FlatFileParser class to transform non-XML source documents:
SAXON can also invoke XML Convert, in order to write the result tree as a flat file, the format of which is described in an XFlat schema.
XML Convert includes a public Java class, named com.unidex.xflat.Sax2FlatFileBuilder, which can be invoked by SAXON as an output method. (The Sax2FlatFileBuilder class is an implementation of the SAX 2.0 org.xml.sax.ContentHandler interface.)
If you specify the com.unidex.xflat.Sax2FlatFileBuilder class as the output method of your XSLT stylesheet, then SAXON will transform the source document into a target flat file, the layout of which is specified in an XFlat schema. Thus, SAXON will write flat file data to the result file. Specifically, SAXON will transform the source document into a result tree, and will pass the result tree to XML Convert as a stream of SAX2 document events. XML Convert will verify that this stream conforms to the specified XFlat schema, and will convert this stream into the target flat file data.
The following is an example of an XSLT stylesheet that specifies the com.unidex.xflat.Sax2FlatFileBuilder class as the output method:
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output xmlns:saxon="http://icl.com/saxon" method="saxon:com.unidex.xflat.Sax2FlatFileBuilder" /> <!-- The rest of the stylesheet goes here. --> </xsl:stylesheet>
Note that the method attribute in the xsl:output instruction specifies the com.unidex.xflat.Sax2FlatFileBuilder class as the output method. The value of the method attribute must be in the http://icl.com/saxon namespace.
When you specify the Sax2FlatFileBuilder class as SAXON's output method, you'll also need to specify the name of the XFlat schema file and name of the output file via system properties. The Sax2FlatFileBuilder class supports the following system properties:
For more information about these system properties, please see the javadoc for the com.unidex.xflat.Sax2FlatFileBuilder class.
In the following example, we invoke SAXON from the command line, in order to transform an XML document (i.e., data.xml) into a flat file (i.e., data.txt) using an XSLT stylesheet (i.e., data.xsl). The stylesheet specifies the Sax2FlatFileBuilder class as the output method. The command, which is quite long, is displayed as multiple lines for readability. However, when invoking this command at the command prompt, you should enter it as a single line.
java -Dcom.unidex.xflat.schema-file-name-2=data.xfl -Dcom.unidex.xflat.suppress-startup-message=true -Dcom.unidex.xflat.flat-file-name=data.txt com.icl.saxon.StyleSheet data.xml data.xsl
The command above is equivalent to the following two commands, in which SAXON transforms the data.xml file into a temporary file (i.e., tmp.xml), which the xml2flat application then converts into a flat file (i.e., data.txt):
java com.icl.saxon.StyleSheet -o tmp.xml data.xml data_xml_output.xsl java xml2flat -s data.xfl tmp.xml data.txt
The data_xml_output.xsl stylesheet is equivalent to the data.xsl stylesheet, with the exception that the xsl:output instruction in the data_xml_output.xsl stylesheet contains the method="xml" attribute. In other words, the data_xml_output.xsl stylesheet does not specify the Sax2FlatFileBuilder class as the output method.
The following sections of the Examples page further illustrate how to invoke SAXON, such that it uses the Sax2FlatFileBuilder class as the output method:
Copyright © 1999 - 2007 Unidex, Inc. |