xsl:import restrictions

Subject: xsl:import restrictions
From: Andrew Kimball <akimball@xxxxxxxxxxxxx>
Date: Wed, 8 Mar 2000 14:21:20 -0800
The XSLT spec says:
1. "Since xsl:import elements are required to occur before any definitions
or template rules, an implementation that processes imported stylesheets at
the point at which it encounters the xsl:import element will encounter
definitions and template rules in increasing order of import precedence."

However, this restriction seems not to simplify implementation because of
another rule mentioned in that same section:
2. "When xsl:include is used to include a stylesheet, any xsl:import
elements in the included document are moved up in the including document to
after any existing xsl:import elements in the including document".

Take the following stylesheets as an example:

<!-- simple.xsl -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
	<xsl:variable name="foo" select="2"/>

	<xsl:template match="/">
		<xsl:value-of select="$foo"/>
	</xsl:template>

	<xsl:include href="simple.inc"/>
</xsl:stylesheet>

<!-- simple.inc -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
	<xsl:import href="simple2.inc"/>
</xsl:stylesheet>

<!-- simple2.inc -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
	<xsl:variable name="foo" select="1"/>
</xsl:stylesheet>

If I'm parsing each stylesheet without caching, I first encounter the
declaration of "foo".  This declaration has the highest import priority.
Then, I encounter the xsl:include.  I parse the simple.inc file and find an
xsl:import.  Last, I parse the simple2.inc file and find another declaration
of "foo", which has a lower import priority.  Now, according to spec
statement #1, the reason for this arbitrary restriction on xsl:import is to
allow implementations to encounter definitions in increasing order of import
precedence.  But my example shows that this isn't true for the xsl:include
case (I find higher "foo" before finding lower "foo").  So for this special
xsl:include case, I will need to do more than simply allowing document order
to determine precedence.

Since implementations have to add this extra re-ordering or precedence
comparison logic anyway, in order to handle the xsl:include case, why bother
restricting the xsl:import instruction at all?  Is there something I'm
missing?

~Andy Kimball


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread