This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: : Setting the value of variables, conditionally.
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl]: Setting the value of variables, conditionally.
- From: Aparna Joshi <aparna dot joshi at Dejima dot com>
- Date: Fri, 13 Jul 2001 09:13:39 -0700
- Reply-To: xsl-list at lists dot mulberrytech dot com
Thanks, Mike!
But, is there any other way because, I have many variables and many
conditions. And, I am trying to minimize the conditional checking to have
something like :-
<xsl:when>... set variable....</xsl:when>
But this shows only the default value once it is out of the <xsl:when>
scope.
Aparna
-----Original Message-----
From: Michael Kay [mailto:mhkay@iclway.co.uk]
Sent: Friday, July 13, 2001 9:10 AM
To: xsl-list@lists.mulberrytech.com
Subject: RE: [xsl]: Setting the value of variables, conditionally.
Set the variables within the global variable declaration, e.g
<xsl:variable name="globalVar2">
<xsl:choose>
<xsl:when test="count(parent/element1)>0">CONDVAL12</xsl:when>
<xsl:when test="count(parent/element2)>0">CONDVAL22</xsl:when>
</xsl:choose>
</xsl:variable>
Mike Kay
Software AG
> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of
> Aparna Joshi
> Sent: 13 July 2001 16:46
> To: 'xsl-list@lists.mulberrytech.com'
> 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'
> xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
>
> <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:choose>
> <xsl:when test="count(element1)>0">
> set globalVar1="CONDVAL11"
> set globalVar2="CONDVAL12"
> </xsl:when>
> <xsl:when test="count(element2)>0">
> set globalVar1="CONDVAL21"
> set globalVar2="CONDVAL22"
> </xsl:when>
> <xsl:choose>
>
> <!-- Display the variables in the HTML page -->
> <html>
> <head>
> <title>
> <xsl:value-of select="$globalVar1" />
> </title>
> </head>
> <body>
> <b>
> <xsl:value-of select="$globalVar2" />
> </b>
> </body>
> </html>
> </xsl:template>
> </xsl:stylesheet>
>
>
> The xml structure could be...
> <parent>
> <element1> ... </element1>
> <element2> ... </element2>
> </parent>
>
> 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.
>
>
> Thanks in advance for any help/suggestion.
>
> Aparna
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list