Re: [xsl] stylesheet expansion

Subject: Re: [xsl] stylesheet expansion
From: Abel Braaksma <>
Date: Mon, 10 Dec 2007 01:28:22 +0100
Geert Bormans wrote:

Correct, I will maintain them separately of course,
but my customer has to fit the chain in, in an application that is not to be touched.
I will deliver in seperate stylesheets, but I would like to have some backup if the importing should fail, caused by path issues eg.
(I have no control over the execution environment)

Considering Colin's remarks, about xsl:next-match etc, it is an exercise which may be next to impossible (at least far from trivial), but I maybe wrong...

Can you change the URIResolver? Because if you can, you can place all stylesheets into one stylesheet, id them (with xml:id), use use-when on them so they won't be called prematurely, and let the URIResolver resolve to parts of the same stylesheet (the id'ed parts). Probably the easiest to do (if this is an option at all) to use your own scheme so any existing schemes are not messed with. If XSLT 2.0 weren't too strict, you would have an easy solution as follows (which illustrates my idea, hopefully the indentation isn't messed with by my Thunderbird...):

<xsl:stylesheet version="2.0"

<xsl:import href="multiple-stylesheets-in-one.xslt#include-me" />
<xsl:template match="/">

<include:stylesheet use-when="0">
<xsl:stylesheet xml:id="include-me" version="2.0" xmlns:xsl="";>
<xsl:template match="/">

Saxon will throw an "A stylesheet cannot import itself" error, even though you aren't really importing oneself. Which is why you will have to come up with your own scheme, or a location of your stylesheet which is not recognized by the processor as being the same:

<xsl:import href="http://otherhost-to-same-location/multiple-stylesheets-in-one.xslt#include-me"; />

but I don't know (not tested), if the #-syntax is supported this way (I remember a few W3C notes on the subject, but I can't recall whether it is legal and whether only the node with "include-me" will get selected).

I'd be curious if this is a feasible path for you, if so, we can elaborate a bit on it.

-- Abel Braaksma

PS: without the xsl:import the use of xsl:stylesheet inside the extension element is legal (at any other place it wouldn't), it is ignored by the XSLT processor.

Current Thread