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

Re: xsl:variable ?

Subject: Re: xsl:variable ?
From: Greg Faron <gfaron@xxxxxxxxxxxxxxxxxx>
Date: Wed, 10 Apr 2002 10:21:56 -0600
xsl variables constant
At 09:53 AM 4/10/2002, you wrote:
<xsl:template name="foo">
  <xsl:variable name="start_x" select="5"/>
  <xsl:if test="true">
    <!-- use the variable and add to it -->
    <xsl:variable name="start_x" select="10"/>

The new variable created here is only within the scope of the if-block.


  </xsl:if>
  <!-- if i use start_x here it just contains 5 and not 10 -->
  <xsl:value-of select="$start_x"/>
</xsl:template>

I have read that xsl:variables are constant so it
would seem that I can not change the value of my
variable, but if this is the case then how can I work
around this problem? I need to store a value to use it
later and manipulate the variable?!

Use recursion and call your named template with a starting parameter.


<xsl:template name="foo">
  <!-- Default value of 5 if none given -->
  <xsl:param name="start_x" select="5"/>
  <xsl:if test="true">
    <xsl:call-template name="foo">
      <xsl:with-param name="start-x" select="$start_x + 5"/>
    </xsl:call-template>
  </xsl:if>
  <xsl:value-of select="$start_x"/>
</xsl:template>

The above template is infinitely recursive because you didn't really provide a purpose for your template. I therefore have no idea what your criteria for stopping is. You'll probably want to add a second param that will get progressively smaller with each recursive call.


Greg Faron Integre Technical Publishing Co.



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.