xsl-list
[Top] [All Lists]

RE: [xsl] Numbering in XSLT

2008-06-10 15:43:14
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(_at_)saxonica(_dot_)com> wrote:

From: Michael Kay <mike(_at_)saxonica(_dot_)com>
Subject: RE: [xsl] Numbering in XSLT
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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(_at_)yahoo(_dot_)com] 
Sent: 10 June 2008 19:55
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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!


      


--~------------------------------------------------------------------
XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


      

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>