RE: [xsl]: Setting the value of variables, conditionally.

Subject: RE: [xsl]: Setting the value of variables, conditionally.
From: "Clapham, Paul" <pclapham@xxxxxxxxxxxxx>
Date: Fri, 13 Jul 2001 09:10:57 -0700
This FAQ appeared yesterday on this list.  Here it is again.

<xsl:variable name="globalVar1">
		<xsl:when test="count(element1)>0">
		<xsl:when test="count(element2)>0">

and the same for globalVar2.


-----Original Message-----
From: Aparna Joshi [mailto:aparna.joshi@xxxxxxxxxx]
Sent: July 13, 2001 08:46
To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
Subject: [xsl]: Setting the value of variables, conditionally.

Hi All, 

Here is the flow of what I have to do. I want to know if its possible using
stylesheet variables.

<xsl:stylesheet version='1.0'

<xsl:variable name="globalVar1">DEFAULTVAL1</xsl:variable>
<xsl:variable name="globalVar2">DEFAULTVAL2</xsl:variable>

<xsl:template match="parent">
<!-- compute and assign value to the variables declared above-->
		<xsl:when test="count(element1)>0">
			set globalVar1="CONDVAL11"
			set globalVar2="CONDVAL12"
		<xsl:when test="count(element2)>0">
			set globalVar1="CONDVAL21"
			set globalVar2="CONDVAL22"

<!-- Display the variables in the HTML page -->
			<xsl:value-of select="$globalVar1" />
			<xsl:value-of select="$globalVar2" />

The xml structure could be...
	<element1> ... </element1>
	<element2> ... </element2>

So, in the <html> </html> portion the globalVar1 and globaVar2 should show
CONDVALxx   value.    Also, the aim is to keep the number of <xsl:when...>
less and to have a generic <html> </html> code.

 XSL-List info and archive:

Current Thread