ODF XSLT Runner and ODF XSLT Runner Task Examples


The XHTML transformation contained in can be used to transform ODF documents into XHTML. Using ODFXSLTRunner it is not even required to extract the ODF package.

The XHTML style sheet runs only with the SAXON XSLT Processor. Using version 9.1 is recommended.

The following command converts an ODF text document <ODT> into an XHTML document <XHTML>:

java -cp odfxsltrunner.jar:<saxon.jar> org.odftoolkit.odfxsltrunner.Main
   -f net.sf.saxon.TransformerFactoryImpl  -x Pictures/ 
  <ooo-xslt>/export/xhtml/opendoc2xhtml.xsl <ODT> -o <XHTML>

<saxon.jar> is the jar of the SAXON XSLT Processor. <ooo-xslt> is the location of the XSLT stylesheets within an installation. In a typical installation, this is (Linux) or Basis/share/xslt (Windows).

Note: A few changes are necessary to use's XHTML transformation with ODFXSLTRunner. These are available as patch in the issue i115881.

XHTML with referenced images only

The XHTML transformation in the above example extracts all images from the ODF document, regardless whether these are referenced in the XHTML document. To extract only the images that are referenced a list of referenced images may be created by the create-html-img-list.xsl style sheet that is contained in the sample-xslt folder of ODFXSLTRunner. It is applied to the XHTML file, and the target is a text file that contains the references images. Although the input file is an XHTML rather than a ODF file, ODFXSLTRunner may be used to apply the style sheet.

java -jar odfxsltrunner.jar create-html-img-list.xsl -i <XHTML> -o <img-list> 
 unzip <ODT> `<img-list>`

Replace embedded objects with bitmap images

Unlike's HTML filter, the XSLT-based XHTML filter does not convert embedded objects into bitmap images. It is however possible to replace the embedded objects of ODF document with the images that the HTML filter has exported by applying the replace-object.xsl style sheet that is contained in the sample-xslt folder of ODFXSLTRunner to the ODF document.

The following steps are required:

Powered by the Apache CMS.

Apache "ODF Toolkit" is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.

Copyright © 2011 The Apache Software Foundation Licensed under the Apache License, Version 2.0. Contact Us
Apache and the Apache feather logos are trademarks of The Apache Software Foundation.
Other names appearing on the site may be trademarks of their respective owners.