Re: [xsl] newbie--using variables

Subject: Re: [xsl] newbie--using variables
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 22 Jan 2002 16:45:27 +0000
Hi Jitt,

> I'm trying to display an image and for the source, I'd like to use a
> variable because the path to the image will change from time to time.  
> Is something like this possible?  If not, can anyone suggest another 
> way?  Here is an example:
>
> I declare my variable on top and use it down below:
>
> <xsl:variable name="logo"> 
>         <xsl:choose> 
>                 <xsl:when test="//xsl_logo='Y'">
>                         <img height="40" 
> src="\\csmpls18m\data\application\images\nsslogoblue.gif" 
> width="120"></img>
>                 </xsl:when> 
>         </xsl:choose> 
> </xsl:variable> 
>
> <td valign="top"><xsl:value-of select="$logo"/>

Sure, that's fine. The only problem that you'll find is that if you
get the *value* of the $logo variable, you'll end up with nothing,
because the img element that you create is an empty element and
therefore has no string value. You should instead use the xsl:copy-of
element to create a *copy* of the content of the $logo variable:

  <xsl:copy-of select="$logo" />

And that will insert the img element in your document.

(By the way, having a single xsl:when inside an xsl:choose is exactly
the same (but longer!) as having an xsl:if.)

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread