[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Dynamic include

Subject: Re: Dynamic include
From: Peter Davis <pdavis152@xxxxxxxxx>
Date: Thu, 12 Sep 2002 03:48:26 -0700
xsl dynamic include
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.