ocsk7
ocsk7

Reputation: 11

XSLT 3 how to write a package

I tried to learn package then I started and copied the working example from the xslt 3 specification but I cannot use the package. In the template where I use I got an error: The package cannot be found.

What did I do wrong? I expect something with name or xmlns declaration The only thing I changed is http://example.com/csv-parser to http://flexibatch.com/fhx-parser and its related xmlns declaration. Flexibatch.com is as fictional as example.com

Thanks for your help

Upvotes: 0

Views: 727

Answers (2)

Martin Honnen
Martin Honnen

Reputation: 167401

If you are running Saxon 9 inside oXygen, then I think one option to use packages is the create and use a Saxon configuration file (oXygen supports creating that file type with new file -> Saxon configuration where you have an option to open the section [xsltPackages] where you can then relate the name of a package to a sourceLocation or exportLocation).

Then in the transformation scenario in the extended Saxon options you can specify the Saxon configuration file to use and that way Saxon will know how to find any package your main module uses with xsl:use-package (https://www.w3.org/TR/xslt-30/#element-use-package) because it can relate the URI/name given there to a package location.

It is a bit of a complicated setup, perhaps add a tag for oXygen so that their support guys see your question and can tell you any more or easier options.

An example section from a Saxon config file to use the package directly from the XSLT 3 test suite is

 <xsltPackages>
      <package name="http://example.com/csv-parser" version="1.0"
           sourceLocation="https://github.com/w3c/xslt30-test/raw/master/tests/decl/package/package-100.xsl"/>
 </xsltPackages>

of course you can adapt the source location if you have a local file and you need to adapt the name if you have done that as your question suggests.

The XSLT code to use that package is online viewable at https://github.com/w3c/xslt30-test/blob/master/tests/decl/package/package-100a.xsl (or executable/downloadable at https://github.com/w3c/xslt30-test/raw/master/tests/decl/package/package-100a.xsl) and is

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:csv="http://example.com/csv"
    exclude-result-prefixes="xs csv" version="3.0">

    <xsl:output indent="yes"/>

    <!-- example input "file"  -->
    <xsl:variable name="input" as="xs:string"
        >name,id,postal code 
        "Abel Braaksma",34291,1210 KA
        "Anders Berglund",473892,9843 ZD</xsl:variable>

    <!-- entry point -->
    <xsl:template name="xsl:initial-template">
        <xsl:copy-of select="csv:parse($input)"/>
    </xsl:template>

    <xsl:use-package name="http://example.com/csv-parser" package-version="*"/>


</xsl:stylesheet>

So you could start a transformation scenario in oXygen with the XSLT code linked directly from https://github.com/w3c/xslt30-test/raw/master/tests/decl/package/package-100a.xsl and the Saxon 9 specific settings using a configuration file with the above section.

Upvotes: 1

ocsk7
ocsk7

Reputation: 11

It works with the config file but now I get an error message: « Cannot apply cascading transformation. Reason: .org.xml.sax.SAXParseException; systemId: file:/C:/..../Test-Package.xsl_xslt_cascade; lineNumber: 3; columnNumber: 9; Content not allowed in prolog. » (line 3 is xmlns:xsl=....)

Upvotes: 0

Related Questions