Doing XSL and FOP transformations on the commandline using Saxon and Apache FOP

by Wolfram Saringer  (2014-11-28)
last change: 2014-11-28

Transfomation using Saxon:
# java -jar saxon9.jar -s:<inputfilename> -xsl:<xsl filename> -o:<outputfilename>

Classpath must include all jars necessary for FOP:
# for name in fop-1.1/lib/*.jar; do export CLASSPATH=$name:$CLASSPATH; done;

Use output from another transformation, i.e. an FO-File:
# java -classpath $CLASSPATH org.apache.fop.cli.Main -fo <fo filename> -pdf <pdf outputfilename>

Use internal transformation mechanism, i.e. input is xml, xsl file transforms to fo:
# java -classpath $CLASSPATH org.apache.fop.cli.Main -xml <xml input filename> -xsl <xsl filename> -pdf <pdf outputfilename>

A complete step from XML to PDF might look like this, using input.xml, transform2fo.xsl and output.pdf als filenames:

Using Saxon:
# java -jar saxon9.jar -s:input.xml -xsl:transform2fo.xsl
# java -classpath $CLASSPATH org.apache.fop.cli.Main -fo -pdf output.pdf

Using only Apache FOP:
# java -classpath $CLASSPATH org.apache.fop.cli.Main -xml input.xml -xsl transform2fo.xsl -pdf output.pdf

all articles represent the sole opinion of their respective author. all content comes without any warranty for correctnes, despite due diligence.