473,325 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Global variable not working in my XSL

his question has probably been asked a million times, but I can't get
this to work.

I'm trying to create a global variable that contains some HTML so that
I can reference it from multiple templates. For some reason, the
templates don't seem to be able to see this variable. What am I doing
wrong? Here is a snip of my code:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="MasterSpacer">
<tr>
<td height="20"/>
</tr>
</xsl:variable>

<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" type="text/css"
href="/stylesheet/MyStyles.css"/>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" align="center">
<xsl:apply-templates select="data/header"/>
<xsl:apply-templates select="data/body"/>
</table>
</body>
</html>
</xsl:template>

....

<xsl:template match="body">
<xsl:copy-of select="$MasterSpacer"/>

....

Jul 20 '05 #1
3 1506
What am I doing
wrong? Here is a snip of my code:


As far as I can see, whatever you are doing wrong, it must be in the
part of your code that was snipped.

David
Jul 20 '05 #2
Here is the complete XSL with XML to test with it. Based on what I've
read, this should work.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="MasterSpacer">
<tr>
<td height="20"/>
</tr>
</xsl:variable>
<!-- The root of the data xml -->
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" type="text/css"
href="/stylesheet/MyStyles.css"/>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" align="center">
<xsl:apply-templates select="data/header"/>
<xsl:apply-templates select="data/body"/>
</table>
</body>
</html>
</xsl:template>
<!-- The criteria section of the report. -->
<xsl:template match="header">
<table border="1" cellpadding="1" cellspacing="1" align="center">
<tr>
<th align="center" colspan="2">My Header</th>
</tr>
<tr>
<td align="left" width="100">
<b>Username</b>
</td>
<td align="left" width="100">
<xsl:value-of select="username"/>
</td>
</tr>
<tr>
<td align="left">
<b>Report Date</b>
</td>
<td align="left">
<xsl:value-of select="report_date"/>
</td>
</tr>
</table>
</xsl:template>
<!-- The main body of the document -->
<xsl:template match="body">
<xsl:copy-of select="$MasterSpacer"/>
<tr>
<td>
<table border="1" cellpadding="1" cellspacing="1" align="center">
<tr>
<th align="center" colspan="9">Document Body</th>
</tr>
</table>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<data>
<header>
<username>pthomas</username>
<report_date>05/20/2005</report_date>
</header>
<body/>
</data>

Jul 20 '05 #3

saxon makes the variable content appear (I added the %%%%%%% later:-)

I think your code is correct and your system is less so.

David
$ saxon gv.xml gv.xsl
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<link rel="stylesheet" type="text/css" href="/stylesheet/MyStyles.css">
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" align="center">
<table border="1" cellpadding="1" cellspacing="1" align="center">
<tr>
<th align="center" colspan="2">My Header</th>
</tr>
<tr>
<td align="left" width="100"><b>Username</b></td>
<td align="left" width="100">pthomas</td>
</tr>
<tr>
<td align="left"><b>Report Date</b></td>
<td align="left">05/20/2005</td>
</tr>
</table>
<tr>
<td height="20"></td>%%%%%%%%%%%%%%%%%%%%%%%%%%%%
</tr>
<tr>
<td>
<table border="1" cellpadding="1" cellspacing="1" align="center">

<tr>
<th align="center" colspan="9">Document Body</th>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Matt | last post by:
Greetings, What are people's thoughts on global variables in C++? Why are we taught not to use them in programming? Is it true that if you are running two copies of the C program one copy can...
4
by: Andrew V. Romero | last post by:
I have been working on a function which makes it easier for me to pull variables from the URL. So far I have: <script language="JavaScript"> var variablesInUrl; var vArray = new Array(); ...
4
by: Dan Elliott | last post by:
Hello, Converting from a working C program to C++, I run into the following error: I have a header: (header.h) namespace shared{ ... struct X{ ...
17
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm...
3
by: tafs7 | last post by:
My code below is supposed to email me when an error occurs on the application, but it's not emailing anything. Am I missing something? I know the smtp servers I've tried work. I even added a...
41
by: Miguel Dias Moura | last post by:
Hello, I am working on an ASP.NET / VB page and I created a variable "query": Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query =...
9
by: Shapper | last post by:
Hello, I am declaring a variable in my aspx.vb code as follows: Public Class catalogue Public productid As String Private Sub Page_Load ... I have an image button where I call the...
9
by: Ed Jensen | last post by:
I'm having a vexing problem with global variables in Python. Please consider the following Python code: #! /usr/bin/env python def tiny(): bar = for tmp in foo: bar.append(tmp) foo = bar
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.