When not to <xsl:include>

Subject: When not to <xsl:include>
From: Mike Brown <mbrown@xxxxxxxxxxxxx>
Date: Tue, 1 Jun 1999 22:23:31 -0600
<xsl:include> and <xsl:import> can only refer to complete stylesheets. Thus,
something like this is fine:

variables.xsl:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0";>
	<xsl:variable name="Title" expr="/give/me/some/data"/>
	<xsl:variable name="Author" expr="'James Clark'"/>
</xsl:stylesheet>


stylesheet.xsl:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0";>
	<xsl:include href="variables.xsl"/>
	<xsl:template match="/">
		<xsl:text>Title: </xsl:text><xsl:value-of select="$Title"/>
		<xsl:text>&#xA;</xsl:text>
		<xsl:text>Author: </xsl:text><xsl:value-of
select="$Author"/>
	</xsl:template>
</xsl:stylesheet>

But what if I want to re-use the contents of the <xsl:template>? I can't use
the same method to import those from another file, because <xsl:text> and
<xsl:value-of> are not allowed at the top level of the stylesheet. Is using
external entity references the preferred method? And is this how to do it
(below)? This works, but I'd just like some confirmation that that's the way
it's supposed to be done.

[variables.xsl as above]

reusable_stuff.txt:
<xsl:text>Title: </xsl:text><xsl:value-of select="$Title"/>
<xsl:text>&#xA;</xsl:text>
<xsl:text>Author: </xsl:text><xsl:value-of select="$Author"/>

stylesheet.xsl:
<?xml version="1.0"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY ShowInfo SYSTEM 'reusable_stuff.txt'> ]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0";>
	<xsl:include href="variables.xsl"/>
	<xsl:template match="/">
		&ShowInfo;
	</xsl:template>
</xsl:stylesheet>



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


Current Thread