[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Choose variable

Subject: Re: Choose variable
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 1 Jul 2003 11:09:04 +0100
xsl choose variable
Hi Ricardo,

> I have an element that I want to modify its value. For example when is 1
> I want 10, 2 -> 15, 3 ->25 and so on.
> How can I do that knowing that I use it on different places and I don't
> want to go putting "xsl:choose" on all of that places. It would be much
> code repeated.
> I've tried to put the value on a variable inside an "xsl:choose" but It
> is impossible to have many variables with the same name.

Instead of putting the variable inside the <xsl:choose>, put the
<xsl:choose> inside the variable:

  <xsl:variable name="newValue">
    <xsl:choose>
      <xsl:when test=". = 1">10</xsl:when>
      <xsl:when test=". = 2">15</xsl:when>
      <xsl:when test=". = 3">25</xsl:when>
      ...
    </xsl:choose>
  </xsl:variable>

and then reuse $newValue wherever you need it.

If you need it in different templates, on the other hand, then you
should create a separate template that contains the <xsl:choose> and
call that template whenever you need the relevant value; the value
itself won't be reused, but the code that calculates it can be. Let us
know if you want to see how to do that.

Cheers,

Jeni

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


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.