2009-10-20

Ant Task to Process XSLT Including XInclude

Ant's built-in task xslt seems to have problem to transform XML documents which use XInclude. With simple documents and xslt based script, I couldn't correct result with the following warning message saying that it couldn't process XInclude.

[xslt] Element include in namespace 'http://www.w3.org/2001/XInclude' encountered in book, 
but no template matches.

I had searched Google to find the same cases and solutions for a few hours, but I couldn't found the helpful one.

But, using java task of Ant, I can write working script for documents using XInclude.
The following is my script.

 <artifact:dependencies pathId="dependency.classpath" filesetId="dependency.fileset">
  <dependency groupId="xerces" artifactId="xercesImpl" version="2.9.1" />
  <dependency groupId="xalan" artifactId="xalan" version="2.7.1" />
  <dependency groupId="saxon" artifactId="saxon" version="6.5.3" />
  <dependency groupId="net.sf.docbook" artifactId="docbook-xml" 
    version="5.0-all" classifier="resources" type="zip" />
  <dependency groupId="net.sf.docbook" artifactId="docbook-xsl" 
    version="1.74.3" classifier="resources" type="zip" />
  <dependency groupId="net.sf.docbook" artifactId="docbook-xsl" 
    version="1.74.3" classifier="ns-resources" type="zip" />
  <dependency groupId="net.sf.docbook" artifactId="docbook-xsl-xalan" version="1.0.0" />
  <dependency groupId="net.sf.docbook" artifactId="docbook-xsl-saxon" version="1.0.0" />
  <dependency groupId="org.apache.xmlgraphics" artifactId="fop" version="0.93"/>
 </artifact:dependencies>

 <target name="build-spec-xhtml-using-java-saxson-6">
  <delete file="${target.base}/spec/xhtml/spec.html"/>
  <java classname="com.icl.saxon.StyleSheet" fork="yes" 
        dir="." failonerror="true">
   <classpath refid="dependency.classpath" />
   <sysproperty key="javax.xml.parsers.DocumentBuilderFactory"
    value="org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/>
   <sysproperty key="javax.xml.parsers.SAXParserFactory"
    value="org.apache.xerces.jaxp.SAXParserFactoryImpl"/>
   <sysproperty key="org.apache.xerces.xni.parser.XMLParserConfiguration"
    value="org.apache.xerces.parsers.XIncludeParserConfiguration"/>
    
   <arg line="-o ${target.base}/spec/xhtml/spec.html"/>
   <arg line="-l"/>
   <arg line="./spec/spec.docbook"/>
   <arg line="${docbook.xsl.dir}/xhtml/docbook.xsl"/>

   <!-- parameters for XSLT -->
   <arg line="toc.max.depth=3"/>
   <arg line='generate.toc="book toc,title,figure,table,example,equation"'/>
   <arg line="use.extensions=1"/>
   <arg line="part.autolabel=1"/>
   <arg line="chapter.autolabel=1"/>
   <arg line="section.autolabel=1"/>
   <arg line="section.label.includes.component.label=1"/>
   <arg line="section.autolabel.max.depth=4"/>
   <arg line="appendix.autolabel=A"/>
   <arg line="chunker.output.indent=yes"/>
   <arg line="chunker.output.encoding=UTF-8"/>
   <arg line="html.stylesheet=docbook-freebsd.css"/>
   <arg line="generate.id.attributes=1"/>
   <arg line="para.propagates.style=1"/>
   <arg line="entry.propagates.style=1"/>
   <arg line="emphasis.propagates.style=1"/>
   <arg line="phrase.propagates.style=1"/>
  </java>
 </target>

For more information, refer the followings.

0 comments:

Post a Comment