This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Dynamic include
- From: Peter Davis <pdavis152 at attbi dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Thu, 12 Sep 2002 03:48:26 -0700
- Subject: Re: [xsl] Dynamic include
- References: <3D806B7E.1070703@u-mangate.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
On Thursday 12 September 2002 03:25, Cédric Claus wrote:
> Now I want to do a dynamic include depending on a tag of my XML document.
> For example:
> xml: <include>page1.xsl<include>
> principal.xsl : <xsl:include><xsl:attribute name="href"><xsl:valueof
> select"include"/></xsl:attribute></xsl:include>
I see a couple options, probably not the only ones:
* If you can make your processor support it, use the <?xml-stylesheet?>
processing instruction to point to an XSL file that includes the custom
stylesheet and also the principal stylesheet. The processing-instruction
replaces the <include> tag.
For example:
+ In your XML:
<?xml-stylesheet href="include-page1.xsl"?>
<other-tags>
...
</other-tags>
+ In include-page1.xsl:
<xsl:stylesheet ...>
<xsl:include href="path/to/principal.xsl"/>
<xsl:template name="custom-processing-for-page1">
...
</xsl:template>
</xsl:stylesheet>
* Or, why not make the source XML with the <include> tag into a stylesheet of
its own? This will involve two stages of processing: the first outputs a
stylesheet containing only the <xsl:include> elements, and the second uses
the newly generated stylesheet to re-process the data using the included
stylesheets. For example:
+ Output from first stage:
<xsl:stylesheet ...>
<xsl:include href="principal.xsl"/>
<!-- taken from <include> element -->
<xsl:include href="page1.xsl"/>
</xsl:stylesheet>
+ Second stage uses the first stage's output stylesheet, and processes the
input XML again (this time ignoring the <include> element).
It should be possible to optimize the two stages to keep from parsing the
source XML twice, by reusing the DOM tree if the data will fit into RAM.
HTH
--
Peter Davis
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list