xsl-list
[Top] [All Lists]

RE: Retaining value of a Global variable

2004-07-16 15:31:15
Hi Vivek,

XSLT does not allow variables to change. Think of them as constants.
You'll need to rethink your approach, I'm afraid.

HTH,
<prs/>

-----Original Message-----
From: Vivek Shinde [mailto:Vivek(_dot_)Shinde(_at_)sas(_dot_)com] 
Sent: Friday, July 16, 2004 4:04 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Retaining value of a Global variable

Hi,

I have a global variable defined at the top of my stylesheet. When I try to
use it subsequently it gets reinitialized. Here's the code.

 <xsl:variable name="whead" select="'No'" />

<xsl:template match="/newsletter">
.
.
      <xsl:apply-templates select="content/article"
mode="proc_webcastheader" />.

</xsl:template>

<xsl:template match="article" mode="proc_webcastheader"> <xsl:variable
name="artclass" select="normalize-space(metadata/article-classification/.)"
/> <xsl:if test="contains($artclass,'Biz-Webcast')">
          <p><xsl:value-of disable-output-escaping="yes"
select="$whead"/></p>
          <IMG
src="http://www.sas.com/subscriptions/images/hdr_webcast.gif";></IMG>
          <xsl:variable name="whead" select="'Yes'" />
          <p><xsl:value-of disable-output-escaping="yes"
select="$whead"/></p> </xsl:if> </xsl:template>


In the second template when I print whead before the <img> it shows 'No' for
all articles even if I set it to 'Yes' after the <img>. Any clues on how to
retain the value of the variable?

Thanks
Vivek

--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--