xml editor

Supported platforms

Compatible with Windows7 & Mac OS X Snow Leopard

Ready for data server software
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] XSLT Sort and choose last items problem


Subject: Re: [xsl] XSLT Sort and choose last items problem
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 10 Feb 2003 09:50:06 +0000

Hi Ned,

> I currently use XSLT:
> (Snippet:)
> <xsl:for-each select="journal/year/month[last()]">
>         <xsl:for-each select="day[position()>last()-5]">
>                 <xsl:sort order="descending" select="@date"/>
>                 <item>
>                         <xsl:call-template name="item-contents"/>
>                 </item>
>         </xsl:for-each>
> </xsl:for-each>
>
> This does not quite do what I want to do. This is because I am
> unable to select the last 5 days when they span "month" elements.
> For example, when the last day in the XML file is 2 Feb, I want to
> select (in this order) 2 Feb, 1 Feb, 31 Jan, 30 Jan, and 29 Jan. I
> can't figure out how to select the days from January.

Rather than having nested xsl:for-eaches to select first the month and
then the day, you should have one xsl:for-each that jumps straight to
the days. (If you need to get information about the month then you can
use the parent axis to do so.) There's also no need to do a sort since
the days are already in date order, so try:

  <xsl:for-each select="(journal/year/month/day)
                          [position() > last() - 5]">
    <item>
      <xsl:call-template name="item-contents"/>
    </item>
  </xsl:for-each>

Note that the brackets around journal/year/month/day ensure that
position() and last() in the predicate [position() > last() - 5]
applies to all the days in the journal rather than applying to the
days within a particular month.
  
Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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



Current Thread
Keywords
xml
XML Editor | XML Author | WYSIWYG Editors | Schema Editor | XSD Documentation | XSL/XSLT Editor | XQuery | XML Databases | SVN Client
© 2002-2011 SyncRO Soft Ltd. All rights reserved. | Sitemap | Privacy Policy | This website was created & generated with <oXygen/>®XML Editor