RE: [xsl] counting in for each

Subject: RE: [xsl] counting in for each
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 11 Dec 2005 16:22:48 -0000
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