Re: conditional variable assignment

Subject: Re: conditional variable assignment
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 18 May 1999 13:01:46 -0400
At 99/05/18 10:46 -0600, Mike Brown wrote:
>Easy, that is, if you don't mind the fact that your variable only exists
>within the <xsl:if> node and its children. So, the following won't work:
>So, then, is the solution to be found in some less than obvious hierarchy of
>XSL instructions, or is an entirely different approach necessary?

Something along the following lines should work for you:

    <xsl:when test="$color='red'">
      <xsl:call-template name="text-template>
        <xsl:param name="tint" expr="'pink'">
        <xsl:param name="shade" expr="'maroon'">
    <xsl:when test="$color='violet">
      <xsl:call-template name="text-template>
        <xsl:param name="tint" expr="'lavender'">
        <xsl:param name="shade" expr="'indigo'">
      <xsl:call-template name="text-template/>

<xsl:template name="text-template">
  <xsl:variable name="color" expr="Get/Color/From/Some/@Attribute">
  <xsl:param-variable name="tint" expr="'light gray'">
  <xsl:param-variable name="shade" expr="'dark gray'">
  The color is <xsl:value-of select="$color"/>...
  The tint is <xsl:value-of select="$tint"/> (not there, is it?)...
  The shade is <xsl:value-of select="$shade"/> (not there either!)

Note the use of defaults (I copied the ones from the otherwise clause).

I hope this helps.

.............. Ken

G. Ken Holman                  mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd. 
Box 266, Kars, Ontario CANADA K0A-2E0  +1(613)489-0999  (Fax:-0995)
Website: XSL/XML/DSSSL/SGML services outline,  XSL/DSSSL shareware,
         stylesheet resource library, conference training schedule,
         commercial stylesheet training materials, on-line XSL CBT.

 XSL-List info and archive:

Current Thread