|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Applying a named template to arbitrary content
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.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








