Re: [xsl] XSLT template library creation

Subject: Re: [xsl] XSLT template library creation
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 15 Oct 2002 16:28:47 +0100
Hi Marco,

> I'd like to create a XSL template library for producing HTML in
> a per-skin way. That is:
> suppose you have a multi-skin site; each user is able to select the skin
> he likes; the output, e.g. XHTML page, is produced by a XML->XSLT transformation.
> My idea is to develop a set of named-templates that abstracts presentation
> widgets (table, button, list, ...).
> So we have two type of XSL:
> 1) one that is skin-indepedent (it uses the per-skin XSL template library)
> 2) one that is skin-dependent (i.e. the per-skin template library)
>
> the number 1) will include the XSL document related to current skin:

It will probably be easier to say that (2) includes/imports (1) rather
than vice versa. You can't do conditional imports using XSLT, so it
will generally be easier, in terms of coding the transformation, to
pick the stylesheet based on the skin that you want rather than having
a single stylesheet and then picking the skin by modifying that
stylesheet as a DOM or passing in a parameter.

> So here the problems:
>
> complex widget, like tables, may take complex "data" as parameters; e.g:
>    call-template name="my:table"
>         with-param name="thead" select=??? /
>         with-param name="tbody" select=??? /
>         with-param name="tfooter" select=??? /
>    /call-template
>
> the value for each param may be a RTF (Result Tree Fragment); however, while
> it happens that RTF for "tbody" is taken from XML tree (e.g. <xsl:with-param
> name="tbody" select="/root/nodes" />"), RTF for "thead" and "tfooter"
> have to be just created in XSL sheet; for example something like:
>   <xsl:with-param name="thead"
> select="create-rtf(text-node('col1_caption'),text-node('col2_caption'))" />
>
> where "create-rtf" and "text-node" functions are hypothetic XSL function :(

If I understand correctly, you're trying to work out how to create a
node set that contains two text nodes when you know the values of the
strings. Try doing something like:

  <xsl:variable name="rtf">
    <value>col1_caption</value>
    <value>col2_caption</value>
  </xsl:variable>

and then:

  <xsl:with-param name="thead" select="exsl:node-set($rtf)/*" />

to get the node set that you want. I'm afraid that if Sablotron
doesn't support exsl:node-set() (or an equivalent function for
converting result tree fragments into node sets) then you're a bit
stuck. I guess you could make thead and tfooter formatted strings
instead, so do something like:

  <xsl:with-param name="thead" select="'col1_caption;col2_caption'" />

and then have the template pick that apart using a recursive
string-manipulation template.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread