Re: [xsl] counting in for each

Subject: Re: [xsl] counting in for each
From: Andrew Franz <afranz0@xxxxxxxxxxxxxxxx>
Date: Wed, 14 Dec 2005 21:04:49 +1100
A useful technique...

1. In your CSS file, define odd & even rows as follows:
.row0  { color: #FFFFFF; }
.row1  { color: #FFD0FF; }

2. In your XSL stylesheet:

<xsl:for-each select="item">
	<tr class="row{(position() mod 2)}">...</tr>
</xsl:for-each>




Michael Kay wrote:


The usual way to handle such requirements is with code such as this:

<xsl:for-each select="item">
 <xsl:choose>
   <xsl:when test="position() mod 2 = 0">...</xsl:when>
   <xsl:otherwise>...</xsl:otherwise>
 </xsl:choose>
</xsl:for-each>

Withing the for-each, the total number of items is available as the result
of the function last().

Michael Kay
http://www.saxonica.com/




-----Original Message-----
From: Dietmar Klotz [mailto:dklotz@xxxxxxxxxxx] Sent: 09 December 2005 20:12
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] counting in for each



I am making a list with "for each" and if the list is 1 or 3 items it should
change the state of display. And I would also like to change the Icon
depending on how many objects there are....so object 1 has icon 1...object 2
icon 2


So my question. Is it possible to count how many Items there are in a node?
And do I know where I am in a for each?


Thanks to all!

Dietmar Klotz

Current Thread