Packaged Stylesheets

A facility is available from Saxon 9.4 allowing an XSLT stylesheet to be distributed to users in a format such that the source code of the stylesheet is not readily visible. Creating a packaged stylesheet requires Saxon-PE or Saxon-EE; running the stylesheet only requires Saxon-HE, provided that it only uses features that are available with Saxon-HE.

From Saxon 9.6 this facility is also available on .NET.

The stylesheet is distributed in the form of a ZIP file; the format of the content is not strongly encrypted, but requires non-trivial effort to decompile. The ZIP package contains all the stylesheet modules that are needed.

To create the package for distribution, use the following command:

java com.saxonica.ptree.StylesheetPackager stylesheet.xsl

or on .NET,

StylesheetPackager stylesheet.xsl

where stylesheet.xsl is the principal stylesheet module, and is the output file containing the packaged stylesheet.

Running the stylesheet requires both the normal Saxon executable JAR/DLL file (HE or higher), and also the JAR file saxon9-unpack.jar which is included as standard in each Saxon edition. This contains Saxonica-proprietary code issued in compiled form only (not open source), but it does not require a license key to run. To run the stylesheet, use a command such as the following (on a single line):

java -cp saxon9he.jar;saxon9-unpack.jar net.sf.saxon.Transform -s:source.xml -r:com.saxonica.ptree.PackageURIResolver -u:on

or on .NET,

Transform -s:source.xml -r:com.saxonica.ptree.PackageURIResolver -u:on

In this command, the -r option sets a URIResolver that has the task of retrieving obfuscated stylesheet modules from the ZIP file, and the -u option ensures that this URIResolver is used for the main stylesheet module (here as well as for resolving xsl:include and xsl:import references between modules.


Some care is needed with operations that depend on the static base URI. This is interpreted as the location of the packaged stylesheet at the time it is executed, not the original location at the time it was compiled. However, there is no limitation on the URIs that can be used in xsl:include and xsl:import declarations - the original URIs appearing in the source code will be replaced with references to the obfuscated modules within the generated ZIP file.

Use of the document('') function to access the source stylesheet is best avoided.

There is no special handling of schema documents referenced by the stylesheet. The packaged stylesheet does not include any imported schema; this must be distributed separately. The version of the schema used for validating documents at run-time must be consistent with the version used for compiling the stylesheet.