Edit online

Compiling an XSL Stylesheet for Saxon

As of Saxon 12.3, it is possible to export a compiled form of a stylesheet as a JSON or XML file (called a stylesheet export file or SEF). Oxygen XML Editor includes a simple tool called Compile XSL Stylesheet for Saxon (found in the Tools menu) that does this for you.

Use-Cases for a Stylesheet Export File (SEF)

  • Use Saxon-JS to run transformations in a browser - A stylesheet export file (SEF) is needed if you want to use the Saxon-JS product to run transformations in a browser, as in the following example:
    <script type="text/javascript" src="SaxonJS/SaxonJS.min.js"></script>
    <script>
        window.onload = function() {
          SaxonJS.transform({
             stylesheetLocation: "books.sef",
             sourceLocation: "books.xml"
             });
        }     
    </script>
  • Use SEF to run transformations in Oxygen XML Editor - You can also use a stylesheet export file (SEF) in Oxygen XML Editor to apply an XSLT transformation over an XML file. This requires Saxon-EE or Saxon-PE versions of the Saxon product and you must select one of those two versions for the Target when you configure the SEF file. When configuring the XSLT transformation, you will specify the SEF file in the XSL URL field.

Compiling an SEF File

The Compile XSL Stylesheet for Saxon tool can be found in the Tools menu and it compiles a specified stylesheet as a JSON or an XML file (stylesheet export file).

If you choose Saxon-JS as the Target (the type of Saxon product that the export file will be used with), then the compiled stylesheet will be a JSON file with a file extension of .sef by default.

If you choose Saxon-EE, Saxon-PE, or Saxon-HE for the Target, then the compiled stylesheet will be an XML file with a file extension of .xsef by default.

Selecting this tool opens the Compile XSL Stylesheet for Saxon dialog box that allows you to configure some options for conversion.

Figure 1. Compile XSLT Stylesheet for Saxon Dialog Box
This dialog box includes the following options:
XSL URL
Allows you to select URL of the source XSL stylesheet. You can specify the URL by using the text field, the history drop-down, or the browsing actions in the Browse drop-down list.
Output file
You can specify the path where the output file will be saved by entering it in the text field, using the Insert Editor Variables button, or using the browsing actions in the Browse drop-down list.
Open in Editor
Select this option to open the resulting stylesheet export file in the main Oxygen XML Editor editing pane.
Target
Allows you to select the type of Saxon product that the export file will be used with. You can choose Saxon-JS, Saxon-EE, Saxon-PE, or Saxon-HE.
Relocatable
Can be used to control the Saxon -relocate parameter. You can select this option to produce a relocatable export package (SEF) that can be deployed to a different location, with a different base URI.
Set the default namespace for unprefixed element names ("-ns")

Can be used to control the -ns:(uri|##any|##html5) Saxon parameter that defines the handling of unprefixed element names that appear as name tests in path expressions and match patterns in the stylesheet:

  • The ##any value declares that unprefixed names are treated as a test on the local name of the element only. They will match regardless of namespace.
  • The ##html5 value declares that an unprefixed element name will match either a name in the XHTML namespace or a name in no namespace. This option is primarily intended for use when generating stylesheets to run under Saxon-JS in the browser since the resulting behavior is close to that defined by the special rules in the HTML5 specification for XSLT and XPath running against an HTML5 DOM.
  • You can also specify a valid URI by editing the value in the combo box. Specifying a URI sets the default namespace for elements and types (effectively a default value for xpath-default-namespace). Note that an explicit value for this attribute takes precedence.
Use a configuration file ("-config")
Select this option if you want to use a Saxon 12.3 configuration file that will be executed for the XSLT transformation and validation processes. You can specify the path to the configuration file by entering it in the URL field, or by using the Insert Editor Variables button, or using the browsing actions in the Browse drop-down list.
Compile
Use this button to generate the stylesheet export file according the options selected in this dialog box.