XML technologies / XSLT / XSLT 2.0 processors / Saxon 9 / Compiled stylesheets

(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers)

Since version 7.3, Saxon can use precompiled stylesheets. Faster stylesheet loading improves transformation efficiency and speed by roughly a factor of two to three.

The invocation of a compiled stylesheet works as described earlier, adding option -c. Supply the compiled filename instead of an ordinary stylesheet. Saxon calls this a Templates object.

First compile a stylesheet into this form. A command-line call can do this too, targeting class java net.sf.saxon.Compile:

java net.sf.saxon.Compile [optionen] stylesheet output

As with command-line transformation, several previously described options are available. Particularly relevant here are -t, -u, -r and -y.

To compile the earlier stylesheet beispiel.xsl without extra options, call:

java net.sf.saxon.Compile beispiel.xsl beispiel.sxx

The compiled file is stored alongside the original and is much larger, here about 6.7 kB versus 0.4 kB. The extension is arbitrary; .sxx is merely Michael Kay’s suggestion.

Calling it is almost like an ordinary transformation. Note option -c and the additional -t used to monitor processing:

java net.sf.saxon.Transform -t -c beispiel.xml beispiel.sxx

Option -t reports actual processing duration for comparison. The result is impressive: execution time (execution time) dropped from 672 ms to 266 ms.

Note – Tied to the Saxon version
Michael Kay emphasizes that a compiled file contains neither machine code nor Java bytecode, so is not truly compiled. Its data is only prepared in a form readable by the Saxon edition that created it.
Recompile the stylesheets after upgrading Saxon rather than reusing older compiled files.

  

 

 

 

back to top