|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Looping using XSL
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








