|
Subject:
|
Static Variables For HTML Header
|
|
Posted By:
|
Parmy
|
Post Date:
|
2/20/2006 1:09:28 PM
|
I'm relatively new to XSLT, at the moment I'm trying to create multiple outputs from a single XSLT file. All the output files contain more or less the same content in the HTML <head> element, except the <title> element.
Rather than repeating the HTML <head> each time it's required between the result-document elements, I have created a global variable called header:
<xsl:variable name"header"> <head> <title>%%title%%</title> </head> </xsl:variable>
Each time I require the header I simply use the:
<xsl:copy-of select="$header">
This works a treat.
The problem I'm having is trying to replace the "%%title%%" text, when I write the $header out.
For instance I have tried:
<xsl:copy-of select="substring-before($header, '%%title%%')"/>NEW TITLE<xsl:copy-of select="substring-after($header, '%%title%%')"/>
All I get back is "NEW TITLE".
Similarly if I try: <xsl:copy-of select="replace($header, '%%title%%', 'NEW TITLE')"/>
If any one has any ideas on this, please help. Basically I want to be able to use a static global variable (which contains HTML elements) which contains a <title> element. When the global variable is written out, I want to be able to put a value of my choice between the <title> tags.
Thanks in advance.
Parmy
|
|
Reply By:
|
mhkay
|
Reply Date:
|
2/20/2006 2:46:32 PM
|
Create a named template to output the header with a parameter
<xsl:template name"header"> <xsl:param name="title"/> <head> <title><xsl:value-of select="$title"/></title> </head> </xsl:template>
Then invoke it as
<xsl:call-template name="header"> <xsl:with-param name="title" select="'Lord of the Rings'"/> </xsl:call-template>
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|