|
Subject: Re: [xsl] xsl:package use question From: "Alan Painter alan.painter@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 10 Feb 2026 06:21:27 -0000 |
Hi Mukul, One of the things that is required for using XSLT packages is that you need to set up the processor to find them. I can offer an example: the project 'ajp' is an XSLT package for which an example XSLT then uses the package: https://github.com/xmljacquard/ajp In SaxonHE for java, you need to compile the innermost packages first and then add them to the compiler to compile the using packages, up to the outermost using package. As an example from https://github.com/xmljacquard/ajp/blob/main/src/main/java/org/xmljacquard/aj p/XsltXpathEnvironment.java The inner package is compiled specially using "compilePackage()" and then imported into a compiler using "importPackage()". public static XsltCompiler getXsltCompiler(final Processor processor) throws SaxonApiException { final XsltCompiler compiler = processor.newXsltCompiler(); final XsltPackage xsltPackage = compiler.compilePackage(getPackageSource()); compiler.importPackage(xsltPackage); return compiler; } The returned compiler is then used to compile the "using" package. I'm hoping that helps and best regards -alan On Tue, Feb 10, 2026 at 7:01b/AM Mukul Gandhi mukulg@xxxxxxxxxxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > Hello xsl-list, > I've been trying to run an XSL stylesheet using xsl:package > instruction to bind two stylesheet modules together, using Saxon XSL 3 > transformer. I've tried with both Saxon-HE 12.9 and Saxon-EE 10.3. > > Following are XSL 3 stylesheet examples that I've tried to run. > > XML document (test1.xml): > > <?xml version="1.0" encoding="UTF-8"?> > <info1/> > > XSL stylesheet 1 (test1.xsl): > > <?xml version="1.0" encoding="UTF-8"?> > <xsl:package name="http://package1" > package-version="1.0.0" > version="3.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:fn0="http://fn0" > exclude-result-prefixes="fn0"> > > <xsl:output method="xml" indent="yes"/> > > <xsl:include href="test2.xsl"/> > > <xsl:use-package name="http://package2" package-version="1.0.0"> > <xsl:accept component="function" names="fn0:abc" > visibility="public"/> > </xsl:use-package> > > <xsl:template match="/"> > <result> > <xsl:value-of select="fn0:abc()"/> > </result> > </xsl:template> > > </xsl:package> > > XSL stylesheet 2 (test2.xsl): > > <?xml version="1.0" encoding="UTF-8"?> > <xsl:package name="http://package2" > package-version="1.0.0" > version="3.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > xmlns:fn0="http://fn0" > exclude-result-prefixes="xs fn0"> > > <xsl:expose component="function" names="fn0:abc" > visibility="public"/> > > <xsl:function name="fn0:abc" visibility="public" as="xs:string"> > <xsl:sequence select="'Hello, ' || fn0:abc1()"/> > </xsl:function> > > <xsl:function name="fn0:abc1" visibility="private" as="xs:string"> > <xsl:sequence select="'..., ref local only function. This > cannot be accessed, from outside this package.'"/> > </xsl:function> > > </xsl:package> > > When I run, an XSL stylesheet test1.xsl using XML document test1.xml as an > input, I get following results with Saxon, > > XTSE3000 Cannot find package http://package2 (version 1.0.0) > Cannot find package http://package2 (version 1.0.0) > > Can anyone, please find an error and let us know, with how I'm using XSLT > and Saxon XSL processor? > > Thanks in advance. > > > -- > Regards, > Mukul Gandhi > XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list> > EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/552232> (by > email <>)
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] xsl:package use question, Mukul Gandhi mukulg@ | Thread | Re: [xsl] xsl:package use question, Mukul Gandhi mukulg@ |
| [xsl] xsl:package use question, Mukul Gandhi mukulg@ | Date | Re: [xsl] xsl:package use question, Mukul Gandhi mukulg@ |
| Month |