This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Looping using 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]