RE: Numbering in XSLT
Hi Michael, Thank you so much for the reply... Incidentally I did the exact same thing 5 minutes prior to reading your post and it works like a charm! Grouping was the key. --- On Wed, 6/11/08, Michael Kay <mike@xxxxxxxxxxxx> wrote: > From: Michael Kay <mike@xxxxxxxxxxxx> > Subject: RE: Numbering in XSLT > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Date: Wednesday, June 11, 2008, 7:59 AM > Your first challenge here is the sorting. I imagine that > 01/01/2007 is a > date, perhaps in dd/mm/yyyy format or perhaps mm/dd/yyyy. > Sorting dates is > easier if you use the international standard format > yyyy-mm-dd (it can > always be reformatted for presentation later - XSLT 2.0 has > a format-date() > function for this). But if you must use this format, you > can sort by > rearranging the date using <xsl:sort > select="concat(substring(@date1, 7, 4), > substring(@date1,....))"/>. > > The next challenge is grouping. This is much easier in XSLT > 2.0 which has an > <xsl:for-each-group> instruction. If for some reason > you're stuck with XSLT > 1.0, google (or look in the index of your XSLT textbook) > for "Muenchian > grouping". It looks complicated but you get the hang > of it. > > Finally, you have to number the groups. That's the easy > bit. Whatever method > of grouping you use, there's likely to be an > <xsl:for-each> instruction to > iterate over the groups, and within that, <xsl:value-of > select="position()"/> will give you a > sequential number. Subtract one to > start at zero. > > Michael Kay > http://www.saxonica.com/ > > > -----Original Message----- > > From: shruta satam > [mailto:the_last_angel_00@xxxxxxxxx] > > Sent: 10 June 2008 19:55 > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > > Subject: Numbering in XSLT > > > > Hello All, > > > > I am an absolute newbee to XSLT and have been cracking > my > > head trying to achieve the following: > > > > Sample XML file: > > > > <date> > > <ed date1="01/01/2007" id="1" > /> > > <ed date1="01/01/2008" id="2" > /> > > <ed date1="01/01/2008" id="3" > /> > > <ed date1="01/01/2005" id="4" > /> > > <ed date1="01/01/2008" id="5" > /> > > <ed date1="01/01/2009" id="6" > /> > > </date> > > > > Now I want a numbered output as follows: > > > > 0. 01/01/2005,4 > > 1. 01/01/2007,1 > > 2. 01/01/2008,2 > > 2. 01/01/2008,3 > > 2. 01/01/2008,5 > > 3. 01/01/2009,6 > > > > i.e I want a numbered o/p grouped by date1 as shown > above. Help!
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format