Re: [xsl] Using xsl:include when converting xsl to xsl

Subject: Re: [xsl] Using xsl:include when converting xsl to xsl
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 27 Feb 2001 12:12:30 +0000
Hi Tim,

> I expected the xsl:template name="body", which is the HTML header
> information contained in functions.xsl, to be added to the resulting
> xsl file but this didn't happen.

The code outputted what I expected it to output, but that doesn't mean
that it's what you expected it to do :)  The only thing 'wrong' is
that the x:namespace-alias result-prefix should be 'x' rather than

<x:namespace-alias stylesheet-prefix="xsl" result-prefix="x"/>

so that the XSLT elements that you're producing are placed in the
correct namespace when they're output.

I think what you're after is a stylesheet that takes an existing
stylesheet with xsl:include elements in it as its source, and expands
the xsl:include elements in the same way as a normal processor would
do to create a result that's also an XSLT stylesheet.

Here is such a stylesheet:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"

<xsl:output method="xml" indent="yes"/>

<xsl:strip-space elements="*" />
<xsl:preserve-space elements="xsl:text" />

<!-- copy elements by default -->
<xsl:template match="*">
      <xsl:copy-of select="@*" />
      <xsl:apply-templates />

<!-- where there are include elements, apply templates to (i.e. copy)
     the content of the xsl:stylesheet element in the document that
     they reference -->
<xsl:template match="xsl:include">
   <xsl:apply-templates select="document(@href)/*/*" />


Note that the above *doesn't* deal properly with xsl:import elements,
but I guess that if you're having to do this with xsl:include then
you're not using xsl:import anyway.

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread