[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Looping using XSL

Subject: Re: Looping using XSL
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 2 Oct 2002 11:24:04 +0100
for looping in xsl
Vasu Chakkera wrote:
> Doesnt <xsl:for-each select="//*[position() &lt;= 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() &lt;= $rating]">
    <div class="moodbar">
      <img src="layout/global/pics/mood-red.gif" alt="" />
    </div>
  </xsl:for-each>
</xsl:template>

The:

  //*[position() &lt;= $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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.