This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Looping using XSL
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 2 Oct 2002 11:24:04 +0100
- Subject: Re: [xsl] Looping using XSL
- Organization: Jeni Tennison Consulting Ltd
- References: <F143U05s5cv2ooBhUaR00010e18@hotmail.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Vasu Chakkera wrote:
> Doesnt <xsl:for-each select="//*[position() <= rating]"> iterate
> through all the child elements of the context node ., in this case
> "mood"..
Actually all the *descendant* elements *in the document* (it's an
absolute path, starting from the root node). The point of the method,
though, is that which nodes it iterates over doesn't actually matter.
But Wendell had a typo which meant this wouldn't work. What he meant
to say was:
<xsl:template match="mood">
<xsl:variable name="rating" select="rating" />
<xsl:for-each select="//*[position() <= $rating]">
<div class="moodbar">
<img src="layout/global/pics/mood-red.gif" alt="" />
</div>
</xsl:for-each>
</xsl:template>
The:
//*[position() <= $rating]
will pick up a node set of N nodes, where N is equal to the value of
$rating. The identities of these nodes doesn't matter, it's just an
easy way to make the content of the xsl:for-each run N times.
This method is known to some of us as "The Piez Method" and to Wendell
himself as "an ugly hack".
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list