Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable scope help needed in XSLT 1

Status
Not open for further replies.

ericchang591

Programmer
Sep 26, 2001
2
US
How would I, in an XSLT stylesheet, create a variable that would be visible globally, but able to be set to different values multiple times?

For example, I am having this problem:

<xsl:choose>
<xsl:when test=&quot;'1'&quot;>
<xsl:variable name=&quot;var&quot; select=&quot;'1'&quot;/>
</xsl:when>
<xsl:eek:therwise>
<xsl:variable name=&quot;var&quot; select=&quot;'2'&quot;/>
</xsl:eek:therwise>
</xsl:choose>

Here, I want to be able to access &quot;var&quot; outside of the choose block, but apparently, it is only visible inside the choose block.
Is there a way?
Thanks
 
you'd have to put the choose block inside a function.

<xsl:template name=&quot;myFunc&quot;>
<xsl:choose>
<xsl:when test=&quot;'1'&quot;>
<xsl:value-of select=&quot;'1'&quot;
</xsl:when
...
...
</xsl:choose>
</xsl:template>

and then in the rest of the code...

<xsl:variable name=&quot;test&quot;>
<xsl:call-template name=&quot;muFunc&quot;/>
</xsl:variable>

then you can use $test

HTH
 
Thanks MrTom, that was exactly what I was looking for! It all works now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top