Re: [xsl] stylesheet organisation

Subject: Re: [xsl] stylesheet organisation
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Sat, 03 Sep 2011 14:59:28 +0100
On 03/09/2011 09:17, Jesper Tverskov wrote:
Mark asked:

"Is there a significant difference between xsl:import and xsl:include
worth learning?"

The only difference between xsl:import and xsl:include is that
xsl:import must be the very first child of xsl:stylesheet.

This means that if the importing stylesheet has templates that matches
with same priority as the templates in the imported stylesheet, the
templates in the importing stylesheet are sure to win out because they
are after the templates in the imported stylesheet.

That is you never really need to use xsl:import. If you make sure that
an xsl:include is the very first child of xsl:stylesheet, it works
exactly as if xsl:import had been used.


Wrong!

As far as template rules are concerned, it's an error to have two templates matching the same node, but processors are allowed to recover from the error by choosing the one that comes last in declaration order. For a processor that chooses the recovery strategy, xsl:import has the same effect as xsl:include. For a processor that doesn't, the effect is quite different.

But for many other declarations in a stylesheet, like global variables, named templates, and stylesheet functions, having two with the same name at the same precedence is a hard error. You can use xsl:import to override these definitions, you can't use xsl:include.

Michael Kay
Saxonica

Current Thread