RE: [xsl] last(): selecting the last one?

Subject: RE: [xsl] last(): selecting the last one?
From: Jarkko.Moilanen@xxxxxx
Date: Mon, 22 Apr 2002 15:33:41 +0300 (EEST)
Lainaus Jarno.Elovirta@xxxxxxxxx:

> Heppa,
> 
> > The situation is a bit more complex than that and I did not express my
> > self clearly....  
> > 
> > The sorting is done by this kind of syntax:
> > Sort the topics by date and then sort by clocktime. The final 
> > soring is done by the topic. (actually the sorting is more
> > complex, but this here needs so far)So the message 
> > order is actually like this:
> >  
> > 
> >    message0 11.10.2001 05:56 topic:harjoitus
> >    message1 12.10.2001 09:45 topic:re:harjoitus
> >    message2 13.10.2001 06:23 topic:re:harjoitus
> >    message3 12.10.2001 11:34 topic:kysmys 
> >    message4 12.10.2001 12:45 topic:re:kysmys  
> 
> Err... these don't seem to be sorted by data, time, topic, as message2
> should be the last one on the list...

Yeah, but this is what I get now and that is what I want =)
> 
> >  and so on...
> > > 
> > > > when xml-file contains several elements (information)and they 
> > > > have element which
> > > > tells the date of input and then there is element that tells the
> > > > clock time of input and another element called subject.  
> > > > 
> > > > How can I find out which one is the last one and
> > > > then select it's subject elements content? 
> 
> Do you want to select the latest one or test is the current node is the
> latest one?
> 
> > > Sort them by date and time (in that order) and then select the
> > > position() = last().
> > 
> > So, if I sort them by that, the order is broken. Can this be 
> 
> I don't get it. If you've already sorted the data by data and time, and
> you need the latest, you already have the sort you want, right? Then
> just select the last one.

Hmmm.... No. Since the order of the result should be like above and then
find the latest concerning both date and time+ select it's topic element 
value. 

> 
> > done by using 
> > some kind of idea like: 
> > check the attribute values time and clock (in that order) and 
> > select the
> > one which has "highest value" in both of them?
> 
> I must be missing something. Ok, how about you do 
> 
> variable name="latest"
>   for-each select="message"
>     sort select="the xpath to sort the data"
>     sort select="the xpath to sort the time"
>     if test="position() = last()"
>       value-of select="generate-id()"
> for-each select="message"
>   <!-- your original sort -->
>     id test="generate-id() = $latest"
>       <!-- do what ever you need -->
> 
> Sorting is expensive and it's monday, so this might make no sense :/
> 
> Cheers,
> 
> Santtu
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 



*******************************************************************
Jarkko Moilanen         *You are wise, witty, and wonderful,      *
Researcher/ ITCM        *but you spend too much time              *
jarkko.moilanen@xxxxxx  *reading this sort of trash.              *
www.uta.fi/~jm60697     *                                         *
GSM: +358 50 3766 927   *                                         *
*******************************************************************
* ITCM Information Technology and Crisis Management               *
*******************************************************************

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread