Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2005, 09:39 AM
PatrickRThomas@hotmail.com
Guest
 
Posts: n/a
Default 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"/>

....

  #2  
Old July 20th, 2005, 09:39 AM
David Carlisle
Guest
 
Posts: n/a
Default Re: Global variable not working in my XSL

[color=blue]
> What am I doing
> wrong? Here is a snip of my code:[/color]

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

David
  #3  
Old July 20th, 2005, 09:39 AM
PatrickRThomas@hotmail.com
Guest
 
Posts: n/a
Default Re: Global variable not working in my XSL

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>

  #4  
Old July 20th, 2005, 09:39 AM
David Carlisle
Guest
 
Posts: n/a
Default Re: Global variable not working in my XSL


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>

 

Bookmarks

Thread Tools

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles