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

Re: Increasing a numerical value in a for-each loop

Subject: Re: Increasing a numerical value in a for-each loop
From: George Cristian Bina <george@xxxxxxxxxxxxx>
Date: Mon, 21 May 2007 17:46:37 +0300
Re:  Increasing a numerical value in a for-each loop
It seems that instead of

<xsl:value-of select="165 + increment"/>

you want

<xsl:value-of select="165 + ((position()-1) div 2)*35"/>
in the first case on the xsl:when
and

<xsl:value-of select="165 + ((position()-2) div 2)*35"/>
on the otherwise part.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina - http://aboutxml.blogspot.com/
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


Smar Kjartan Yasin wrote:
Good day,

I've been going through this mailing list and trying to figure out a way to increase a numerical value in a for-each loop. I know I can't use a variable since I can't change its value after it's been set.

The code:
--snip--
<xsl:for-each select="//Ticket">
<xsl:choose>
<xsl:when test="position() mod 2 = 1">
DIR 4:PP <xsl:value-of select="165 + increment"/>,<xsl:value-of select="230 + //offsets/x"/>:FT "Swiss 721 BT",8:PT "23. mam 2007"
</xsl:when>
<xsl:otherwise>
DIR 4:PP <xsl:value-of select="165 + increment"/>,<xsl:value-of select="515 + //offsets/x"/>:FT "Swiss 721 BT",8:PT "28. mam 2007"
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
--/snip--


As you can see I'm now using position() to alternate between odd and even elements, but I need to increment 165 by 35 each time the for-each loop is run.
I know I can use a template to increment a variable but I don't think that's "The XSL-way".


The output I'm getting now is:
--snip--
      DIR 4:PP 165,230:FT "Swiss 721 BT",8:PT "14. Sept. 406 kl. 19:30"
      DIR 4:PP 165,515:FT "Swiss 721 BT",8:PT "31. Okt. 406 kl. 19:30"
      DIR 4:PP 165,230:FT "Swiss 721 BT",8:PT "30. Nsv. 406 kl. 19:30"
      DIR 4:PP 165,515:FT "Swiss 721 BT",8:PT "8. Feb. 407 kl. 19:30"
      DIR 4:PP 165,230:FT "Swiss 721 BT",8:PT "1. Mar. 407 kl. 19:30"
      DIR 4:PP 165,515:FT "Swiss 721 BT",8:PT "22. Mar. 407 kl. 19:30"
      DIR 4:PP 165,230:FT "Swiss 721 BT",8:PT "20. Apr. 407 kl. 19:30"
--/snip--

But I want to get:
--snip--
      DIR 4:PP 165,230:FT "Swiss 721 BT",8:PT "14. Sept. 406 kl. 19:30"
      DIR 4:PP 165,515:FT "Swiss 721 BT",8:PT "31. Okt. 406 kl. 19:30"
      DIR 4:PP 200,230:FT "Swiss 721 BT",8:PT "30. Nsv. 406 kl. 19:30"
      DIR 4:PP 200,515:FT "Swiss 721 BT",8:PT "8. Feb. 407 kl. 19:30"
      DIR 4:PP 235,230:FT "Swiss 721 BT",8:PT "1. Mar. 407 kl. 19:30"
      DIR 4:PP 235,515:FT "Swiss 721 BT",8:PT "22. Mar. 407 kl. 19:30"
      DIR 4:PP 270,230:FT "Swiss 721 BT",8:PT "20. Apr. 407 kl. 19:30"
--/snip--

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.