This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Looping using XSL
- From: Jarno dot Elovirta at nokia dot com
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 2 Oct 2002 09:23:31 +0300
- Subject: RE: [xsl] Looping using XSL
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi,
> I am trying to use a number in an xml file to define the
> number of times
> an image gets placed on the page. As the number appears only once and
> there are no nodes to count or group I'm a little bit stuck.
>
> The XML looks like this:
> <mood>
> <rating>5</rating>
> </mood>
>
> In this case I want to put five iterations of the image on
> screen like this:
>
> <div class="moodbar"><img
> src="layout/global/pics/mood-red.gif" alt=""
> /></div>
> <div class="moodbar"><img
> src="layout/global/pics/mood-red.gif" alt=""
> /></div>
> <div class="moodbar"><img
> src="layout/global/pics/mood-red.gif" alt=""
> /></div>
> <div class="moodbar"><img
> src="layout/global/pics/mood-red.gif" alt=""
> /></div>
> <div class="moodbar"><img
> src="layout/global/pics/mood-red.gif" alt=""
> /></div>
>
> Is there a way of doing this so if the number is changed
> (with a max of
> 17 possible) the number of images will change?
Recursion is your friend.
template rater
param i
if $i > 0
<div class="moodbar">
<img src="layout/global/pics/mood-red.gif" alt="" />
</div>
call-template rater
with-param i $i - 1
Or you could use the Piez Method, but I remember WP himself saying that "it's a cheat".
Cheers,
Jarno
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list