Subject: Get count of a for loop
Posted By: austinf Post Date: 5/16/2006 2:41:28 AM
hi i would like to get the count of a for loop outside the loop

here is a sample code

<xsl:for-each select="Car">
 <xsl:variable name="level" select="position()"/>        
</xsl:call-template>                        


i would like the number of cars to be stored in a hidden variable on my jsp page. here i can include the hidden field inside the loop with last() called but that will repeat the hidden field the number of times the Car tag is present.

can some one tell me how to acccess the total from outside the for loop

thanks



Reply By: mhkay Reply Date: 5/16/2006 3:26:56 AM
I don't understand all the stuff about hidden variables on jsp pages, but you can count the number of Car elements before entering the for-each with the XPath expression select="count(Car)".

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

Go to topic 44279

Return to index page 286
Return to index page 285
Return to index page 284
Return to index page 283
Return to index page 282
Return to index page 281
Return to index page 280
Return to index page 279
Return to index page 278
Return to index page 277