Skip to content

packages

Dr. Christian Lück edited this page Apr 26, 2024 · 5 revisions

XSLT Packages

General Documentation

Packages were introduced to XSLT in the XSLT 3.0 specification. They are a means for modelling dependencies in a far more fine-grained way than xsl:import and xsl:include.

See the Packages section in the XSLT 3.0 specification.

Using Packages

Note, that in

<xsl:use-package
    name="https://scdh.zivgitlabpages.uni-muenster.de/tei-processing/x2tei-transformations/xsl/pagexml/pagecontent2tei.xsl"
    package-version="1.0.0"/>

the URI https://scdh.zivgitlabpages.uni-muenster.de/tei-processing/x2tei-transformations/xsl/pagexml/pagecontent2tei.xsl is not the location, where the package can be loaded from. It is a package name!

In order for a stylesheet to compile, you have to provide the package location to the XSLT processor. See below.

This means, that there can be several implementation variants of a package with a specific name. You can substitute one implementation with an other one. This makes packages much more flexible than the old xsl:include and xsl:import, where locations were hard-wired.

Saxon

In Saxon, you have two options to provide a package location to the XSLT processor:

  1. the -lib:FILENAME.xsl command line option
    • example:
    target/bin/xslt.sh -lib:target/dependencies/x2tei-transformations/xsl/pagexml/pagecontent2tei.xsl -xsl:xsl/tei/pagexml2tei.xsl -s:test/samples/121030/121030_page/121030_01.xml
    
  2. the xsltPackages section in a Saxon configuration file
    • on the command line, the configuration file can be provided to the Saxon XSLT processor with the -config:FILE command line option.
    • example:
    target/bin/xslt.sh -config:saxon.xml -xsl:xsl/tei/pagexml2tei.xsl -s:test/samples/121030/121030_page/121030_01.xml
    

This x 2 TEI Transformations project and its distributions in build artifacts provides a Saxon configuration file.

oXygen

You can define a Saxon configuration file in your XSLT project, so that your Oxygen knows the upstream packages you use. Go to Options -> Preferences -> XML -> XSLT/XQuery -> XSLT -> Saxon -> Saxon-HE/PE/EE and use the Configuration file option to set up a config file.

BTW: It's a good idea to have an oxygen project and to store this in Project Options, like in the screenshot. Also note the use of the editor variable ${pdu}, which expands to the directory URL (file: scheme) of the currently opened project.

oxygen-saxon-config

The resulting entry in your XPR file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <meta>
        <filters directoryPatterns="" filePatterns="\QHSDE%20Transformations.xpr\E" positiveFilePatterns="" showHiddenFiles="false"/>
        <options>
            <serialized xml:space="preserve">
                <serializableOrderedMap>
                    <entry>
                        <String>key.xml.catalog.option.pane</String>
                        <Boolean>true</Boolean>
                    </entry>
                    <entry>
                        <String>key.xslt.saxon8.option.pane</String>
                        <Boolean>true</Boolean>
                    </entry>
                    <entry>
                        <String>saxon.latest.config.file</String>
                        <String>${pdu}/saxon.ee.xml</String>
                    </entry>
                    <entry>
                        <String>saxon.latest.use.config.file</String>
                        <Boolean>true</Boolean>
                    </entry>
                </serializableOrderedMap>
            </serialized>
        </options>
    </meta>
    <projectTree name="HSDE%20Transformations.xpr">
        <folder path="."/>
    </projectTree>
</project>

Tooling

Please have a look at the Tooling project, which makes handling of Saxon config files very easy!

Clone this wiki locally