2009-05-28T17:56:25Z
Dave Pawson.
link
Home
Saxon ant xslt xInclude and xml catalogs
I've spent too long today wondering why my script to run Saxon 6 XSLT 1.0 wasn't working with xInclude processing, when it should. Lots of replies to google query on same topic..... but none of them seemed to work. Then I read this at Apache.org which had me doing a Homer!
xerces.jar is no longer available in the main distribution. You can still download this jar from deprecated distribution. xerces.jar is a Jar file that contains all the parser class files (i.e., it contains the intersection of the contents of xercesImpl.jar and xml-apis.jar).
Oops. I'd had it in my classpath for XSLT 1.0 for so long it was growing mushrooms. I promptly updated to the latest xerces2-j here. For me, today (May 09) it is version 2.9.1, it may change with time. Note the quote though! it contains the intersection of the contents of xercesImpl.jar and xml-apis.jar. So it is no longer needed! So, for now, my shell script to run Saxon for XSLT 1.0 is
java -cp /myjava/saxon655.jar:/myjava/xercesImpl.jar:/myjava/resolver.jar:/sgml \
-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl \
-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl \
-Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration\
com.icl.saxon.StyleSheet -o $3 $1 $2 "saxon.extensions=1" $4 $5 $6
Note the continuation lines (the backslashes.) Remove them and make it one line if you need to, adjust the path separators as needed for your OS and it should run fine.
I've also included resolver.jar to catalog resolution, picked out the xerces parser and asked it to process xIncludes. It does. Now. Once I removed the inclusion of xerces.jar in my classpath.
The next problem was running the same thing in ant. Less easy to debug. My working solution is below, learning from the above
<property name="infile" value="input.xml"/>
<property name="xslt1_processor" value="com.icl.saxon.StyleSheet"/>
<property name="basedir" value="."/>
<property name="stylesheet" value="MyStylesheet.xsl"/>
<property name="outfile" value="output.html"/>
<property name="infile" value="MyInput.xml"/>
<property name="xslt1_jar" value="saxon655.jar"/>
<property name="resolver_jar" value="resolver.jar"/>
<path id="xslt1.processor.classpath">
<pathelement path="${xslt1_jar}"/> <!-- Saxon jar -->
<pathelement path="${resolver_jar}"/> <!-- resolver jar -->
<pathelement path="${xerces_impl_jar}"/> <!-- xinclude -->
<pathelement path="/sgml"/> <!-- for catalogManager.properties -->
</path>
<target name="xslt" >
<java classname="${xslt1_processor}"
fork="yes"
dir="${basedir}"
failonerror="true">
<classpath refid="xslt1.processor.classpath" />
<jvmarg line="-Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration"/>
<jvmarg line="-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/>
<jvmarg line="-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl"/>
<jvmarg line="-Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration"/>
<arg line="-x org.apache.xml.resolver.tools.ResolvingXMLReader"/>
<arg line="-y org.apache.xml.resolver.tools.ResolvingXMLReader"/>
<arg line="-r org.apache.xml.resolver.tools.CatalogResolver "/>
<arg value="-l"/>
<arg value="-o"/>
<arg value="${outfile}"/>
<arg line="${infile} ${stylesheet}" />
</java>
<tstamp>
<format property="fintim" pattern="E @ H:m a" locale="en,UK"/>
</tstamp>
<echo>Finished at ${fintim}</echo>
</target>
Hope that makes sense. It is a copy of the batch file / script, written for ant (version 1.7 as of today).
Keywords: ant
Comments (View)Return to main index