Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 2nd, 2008, 05:46 AM
Authorized User
 
Join Date: Jun 2008
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default Numbering - For each

Is there a way to number all rows in a for-each statement? I don't need to produce a count, however I need to have the following output.

1 black
2 red
3 green

I need to generate the 1, 2, 3... next to the values.

 
Old July 2nd, 2008, 05:50 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The xpath function position() will give you the position in a for-each loop.

/- Sam Judson : Wrox Technical Editor -/
 
Old July 2nd, 2008, 06:30 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The simplest way is <xsl:value-of select="position()"/>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 2nd, 2008, 07:56 AM
Authorized User
 
Join Date: Jun 2008
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Numbering in XSLT Angel1221 XSLT 1 June 10th, 2008 05:07 PM
Sequential numbering help gear1 Access 1 April 9th, 2007 06:31 AM
Page numbering athanatos XSLT 4 May 13th, 2005 06:12 PM
numbering harag XSLT 2 November 6th, 2003 06:04 AM
XSL numbering be782524 XSLT 2 August 5th, 2003 05:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.