[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Looping using XSL


Subject: Re: [xsl] Looping using XSL
From: "Vasu Chakkera" <vasucv@xxxxxxxxxxx>
Date: Wed, 02 Oct 2002 05:30:42 +0000

Hi,
Doesnt <xsl:for-each select="//*[position() &lt;= rating]">
iterate through all the child elements of the context node ., in this case "mood"..
so essentially since it has only one child element( "rating" ), It should iterate only once irrespective of the condition *[position() &lt;= rating]">
so you xsl should produce only one line.
<div class="moodbar"><img src="layout/global/pics/mood-red.gif" alt="" /></div>
Vasu



From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Looping using XSL
Date: Wed, 02 Oct 2002 00:33:36 -0400

Josh,

This is something shameful, but it works:

<xsl:template match="mood">
  <xsl:for-each select="//*[position() &lt;= rating]">
    <div class="moodbar">
      <img src="layout/global/pics/mood-red.gif" alt="" />
    </div>
  </xsl:for-each>
</xsl:template>

When this was first introduced a couple of years back, there was a discussion of how best to get a large enough set of nodes (the critical bit to avoid having this trick be painfully expensive ... *at least* bind that //* to a variable to avoid traversing it all the time):

<xsl:variable name="plentynodes" select="//*"/>

<xsl:for-each select="$plentynodes[position() &lt;= rating]">...

Note: it is *not* a loop, and is only iteration in some particular sense.

Enjoy,
Wendell

At 11:05 PM 10/1/2002, you wrote:
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?

___&&__&_&___&_&__&&&__&_&__&__&&____&&_&___&__&_&&_____&__&__&&_____&_&&_ "Thus I make my own use of the telegraph, without consulting the directors, like the sparrows, which I perceive use it extensively for a perch." -- Thoreau


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




_________________________________________________________________
Join the world?s largest e-mail service with MSN Hotmail. http://www.hotmail.com



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




Current Thread
Keywords