This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Applying a named template to arbitrary content
- To: XSL-List at mulberrytech dot com
- Subject: Applying a named template to arbitrary content
- From: Iain Huxley <iain at mindspike dot com>
- Date: Sun, 12 Mar 2000 21:22:06 -0800
- Reply-To: xsl-list at mulberrytech dot com
Hi --
I've spent a fair while searching for a solution to a seemingly simple
problem, perhaps someone could help me out...
I'm trying to make a generic template which will, in effect, simply insert
stuff before and after the content. In one case, I want to do it to apply
font styling parameters etc. where needed:
e.g.
...
<font size="4" color="#ffffff">
<b>
...content...
</b>
</font>
..
The catch is that I want the content to be arbitrary - sometimes it would
simply be <xsl:apply-templates/>, sometimes it might be a call to another
named template, or it might be a series of elements and text.
The closest I've got is by always calling <xsl:apply-templates/> within the
template
e.g.
<xsl:template name="FontAppearance">
<font size="4" color="#ffffff">
<b>
<xsl:apply-templates/>
</b>
</font>
</xsl:template>
usage:
<xsl:call-template name="FontAppearance"/>
however, this isn't great since I want to be able to apply the style to
anything, such as a call to a named template.
In order to solve this, I tried assigning the desired content to a
variable, and passing that to the template. (I initally tried putting the
content directly into the param and using <xsl:value-of select="$content">
in the named template, I'm not sure if this should be possible).
e.g.
<xsl:template name="FontAppearance">
<xsl:param name="content">
<font size="4" color="#ffffff">
<b>
<xsl:copy-of select="$content"/>
</b>
</font>
</xsl:template>
usage:
<xsl:variable name="foo">
<!-- content example - call index template -->
<xsl:call-template name="Index"/>
</xsl:variable>
<xsl:call-template name="FontAppearance">
<xsl:param name="content">
<xsl:value-of select="$foo">
</xsl:param>
</xsl:call-template>
However, this doesn't work, and it's very clunky considering how regularly
I want to use it in my stylesheet anyway.
Here are some examples of how I'd ideally like to use it:
<xsl:call-template name="FontAppearance_Body1">
<!-- following would be inserted into the FontAppearance template -->
<xsl:call-template name="Index"/>
</xsl:call-template>
<xsl:call-template name="FontAppearance_Heading1">
<xsl:value-of select="Title"/>
</xsl:call-template>
<xsl:call-template name="FontAppearance_Body2">
<xsl:apply-templates select="Sections"/>
</xsl:call-template>
My basic question is - what's the closest I can get to the above
usage? Perhaps I've missed something obvious, it seems like it should be
more straightforward to do what I want.
Thanks in advance,
Iain.
//----------------------------------------------------
// Iain Huxley
// President
// Mindspike Technologies
// http://mindspike.com
// Ph: (510) 339 7789
//----------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list