[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] making trees/lists during execution (dynamically)


Subject: Re: [xsl] making trees/lists during execution (dynamically)
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 9 Feb 2004 16:02:37 +0000

Hi Peter,

> Is it possible to make trees (or lists) dynamically during the
> transformation?

You can build a "result tree fragment", which you assign to a variable
or parameter, and can then copy into the result with <xsl:copy-of>. As
a really simple example, say you wanted to create table cells using a
common template (because the HTML for the table cells was complex in
some way). The content of the table cell needs to be passed in as a
result tree fragment using a parameter, and then copied into the cell
that you create.

The create-table-cell template might look like:

<xsl:template name="create-table-cell">
  <xsl:param name="content" />
  <td ...>
    <xsl:copy-of select="$content" />
  </td>
</xsl:template>

To call it, you'd do something like:

  <xsl:call-template name="create-table-cell">
    <xsl:with-param name="content">
      Various content, <em>including</em> markup.
    </xsl:with-param>
  </xsl:call-template>

The $content parameter here gets passed a result tree fragment: a
small tree, destined for the result, that contains text nodes and
an <em> element. Note that if you use <xsl:value-of> on $content,
you'll get the string value of the result tree fragment, and lose any
markup that it contains.

The one limitation about result tree fragments is that you can't
process them without converting them to node sets. To do that, you
need to use an extension function such as exsl:node-set(). From your
brief description, that might be a problem, or it might be that you
just need to think about what you're trying to do in a different way.

> If needed, I can provide an example, but I hope this is clear
> enough.

If the above doesn't hit the spot, an example would help us understand
what you need to do.

Cheers,

Jeni

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


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



Current Thread