A new facility is available in 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.
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 package.zip
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 file (HE or higher), and also the
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):
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
package.zip) as well as
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: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.