Re: [xsl] importing/including a stylesheet with a dynamic name (c an't)

Subject: Re: [xsl] importing/including a stylesheet with a dynamic name (c an't)
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 31 Jan 2001 18:10:44 +0000
Hi Adam,

> Currently we use quasi XSL documents for the layout and the skin,
> pass them through compiling XSL to create the actual transform that
> we would apply. Since running transforms on the fly is costly
> compared to storing every possible combination of layout and skin,
> we compile all our transform ahead of time. I've thought about
> allowing the layout to specify which skins could be valid (that is
> load them all) and then use parameters to selectively call
> particular skins. This gets rather gruesome if I have a template
> that could concievable use all skins.

Would it be possible to store the information about the layout and the
skin in some XML that just held that information - some 'template.xml'
files for the various layouts and/or some 'skin.xml' files for the
various skins, and then access that information within the stylesheet
to apply it. As a very basic example, say you had a skin defined as:

--- myskin.xml ---
  <style id="foo" background="black" colour="white" />
  <style id="bar" font="Verdana" size="2" />

You could have the name of the skin passed in as a parameter:

<xsl:param name="skin-name" select="'defaultskin'" />

and then access the file for that skin using the document() function
and store it in a global variable:

<xsl:variable name="skin"
              select="document(concat($skin-name, '.xml'))/skin" />

You could then access the style information wherever you wanted to in
the stylesheet:

<xsl:template match="p">
      <!-- copy the attributes of the 'foo' style -->
      <xsl:copy-of select="$skin/style[@id = 'foo']/@*" />
      <xsl:apply-templates />

Would something like that be feasible/helpful?  It would at least mean
that there would only be one transform per request (rather than two,
the first creating the stylesheet for the second).  You might be able
to cache the skins (and/or layouts) in memory for quicker access.



Jeni Tennison

 XSL-List info and archive:

Current Thread