RE: Conditional variable assignment

Subject: RE: Conditional variable assignment
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Thu, 19 Oct 2000 12:07:19 +0100
> <xsl:variable name="style"
>     <xsl:if test="@style_override">
>             style = @style_override
>    </xsl:if>
>     <xsl:if test="not(@style_override)">
>             style =$default_style
>    </xsl:if>
> </xsl:variable>

Try
<xsl:variable name="style" 
select="string((@style_override | $default_style)[last()])"/>

This relies on the fact that the @style_override attribute will be later in
document order than the @default_style attribute.

Mike Kay

> -----Original Message-----
> From: Melvyn Rosengarden [mailto:melrose@xxxxxxxxxxxxxxxx]
> Sent: 18 October 2000 01:30
> To: xsl-list@xxxxxxxxxxxxxxxx
> Subject: Conditional variable assignment
> 
> 
> The root node of my document has a style attribute which serves as the
> default for the entire XML document. Nested subordinate 
> elements MAY have an
> attribute that overrides the document default as shown in the 
> snipet below.
> 
> <root_element default_style="style1">
>     <child>
>         <grandchild style_override="style5"/>
>     </child>
> </root>
> 
> As you might guess the logic of my XSLT says if the grandchild has an
> override use its value otherwise use the default. Once I know 
> which value
> to use I need to construct an <xsl:choose> to know what to do next.
> 
> I created a top-level  (global) variable to capture the 
> default style so it
> will be available when I instantiate the grand child node
> <xsl:variable name="default_style" 
> select="root_element/@default_style />
> 
> Now I THINK I would like to create ONE variable to use in the 
> xsl:choose
> construct.....BUT I can't quite get it right.
> CONCEPTUALLY I want to say:
> 
> <xsl:variable name="style"
>     <xsl:if test="@style_override">
>             style = @style_override
>    </xsl:if>
>     <xsl:if test="not(@style_override)">
>             style =$default_style
>    </xsl:if>
> 
> <!-- Now with the variable "style" set -->
>     <xsl:choose>
>         <xsl:when text="$style=style1">
>                 ....call template1....
>      </xsl:when>
>     <xsl:when text="$style=style2">
>                 ....call template2....
>      </xsl:when>
> 
>  Any help would be greatly appreciated....Thanks
> 
> 
> "You already have zero privacy -- get over it !!
> Melvyn Rosengarden
> melrose@xxxxxxxxxxxxxxxx
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread