Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2006, 02:09 PM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Static Variables For HTML Header

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



 
Old February 20th, 2006, 03:46 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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




Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with static variables behaviour shujamughal ASP.NET 2.0 Professional 4 July 21st, 2007 01:56 AM
non-static reports to static html files miamikk ASP.NET 2.0 Basics 0 June 4th, 2007 01:48 PM
Declaring static variables in ASP lakshmi_annayappa ASP.NET 1.0 and 1.1 Basics 1 May 24th, 2007 06:49 AM
static HTML table border problem Robin1 HTML Code Clinic 4 August 12th, 2004 04:58 AM
who destroy static variables(no instance of class) MikoMax J2EE 1 March 31st, 2004 08:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.