Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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



Reply With Quote
  #2 (permalink)  
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:25 PM.


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