xsl-list
[Top] [All Lists]

Re: [xsl] Increasing a numerical value in a for-each loop

2007-05-21 07:36:27
Recursion! =)

<xsl:template match="Record">
  <xsl:param name="value" />
  <xsl:apply-templates select="following-sibling::Record[1]">
     <xsl:with-param name="value" select="$value + value" />
  </xsl:apply-templates>
</xsl:template>

Or something along that lines. I may have my [1]'s mixed up.

On 5/21/07, Ómar Kjartan Yasin <omar(_at_)midi(_dot_)is> 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. maí 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. maí 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. ´06 kl. 19:30"
       DIR 4:PP 165,515:FT "Swiss 721 BT",8:PT "31. Okt. ´06 kl. 19:30"
       DIR 4:PP 165,230:FT "Swiss 721 BT",8:PT "30. Nóv. ´06 kl. 19:30"
       DIR 4:PP 165,515:FT "Swiss 721 BT",8:PT "8. Feb. ´07 kl. 19:30"
       DIR 4:PP 165,230:FT "Swiss 721 BT",8:PT "1. Mar. ´07 kl. 19:30"
       DIR 4:PP 165,515:FT "Swiss 721 BT",8:PT "22. Mar. ´07 kl. 19:30"
       DIR 4:PP 165,230:FT "Swiss 721 BT",8:PT "20. Apr. ´07 kl. 19:30"
--/snip--

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


--
Kær kveðja,
Ómar Kjartan
Midi.is Ltd.
Reykjavikurvegur 74 - 220 Hafnafjordur, Iceland
Tel: +354 540 9800

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--