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

Subject: RE: [xsl] last(): selecting the last one?
From: Jarno.Elovirta@xxxxxxxxx
Date: Mon, 22 Apr 2002 15:11:24 +0300
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...

>  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.

> 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


Current Thread