[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Sort-grouping problem

Subject: Sort-grouping problem
From: "Ragulf Pickaxe" <jawxml@xxxxxxxxxxx>
Date: Tue, 16 Apr 2002 17:30:57 +0000
xsl sort grouping
Hello all,

I have a problem both sorting and grouping...
I can sort and I can group (using following two templates), but I can't manage to do both and I have been at it for 5 hours now, so now I appeal to you for help.


I have the folling XML:

<NewsList>
<Meta attributeA="AnAttribute">
<One>Just MetaData</One>
<Two>Not important here</Two>
</Meta>
<List>
<News NewsType="1"><Date>03-02-2002</Date><P1>This is a newsletter or some such</P1><P2>The News</P2><P3>More News</P3>
</News>
<News NewsType="2"><Date>03-02-2002</Date><P1>This is a newsletter or some such</P1><P2>The News</P2><P3>More News</P3>
</News>
<News NewsType="2"><Date>06-02-2002</Date><P1>This is a newsletter or some such</P1><P2>The News</P2><P3>More News</P3>
</News>
<News NewsType="2"><Date>04-02-2002</Date><P1>This is a newsletter or some such</P1><P2>The News</P2><P3></P3>
</News>
<News NewsType="2"><Date>05-02-2002</Date><P1>This is a newsletter or some such</P1><P2>The News</P2><P3></P3>
</News>
<News NewsType="2"><Date>04-02-2002</Date><P1>This is a newsletter or some such</P1><P2>The News</P2><P3>The above P3 tags where empty</P3>
</News>
<News NewsType="2"><Date>01-02-2002</Date><P1>This is a newsletter or some such</P1><P2>The News</P2><P3>Yet more News</P3>
</News>
</List>
</NewsList>


I can sort it by Date using simple stylesheet like this:

<xsl:template match="/">
 <xsl:apply-templates select="NewsList"/>
<xsl:template>

<xsl:template match="NewsList">
 <xsl:apply-templates select="List"/>
<xsl:template>

<xsl:template match="List">
<xsl:apply-templates select="News">
<xsl:sort select="substring(Date,7,4)" data-type="number" order="ascending"/>
<xsl:sort select="substring(Date,5,2)" data-type="number" order="ascending"/>
<xsl:sort select="substring(Date,1,2)" data-type="number" order="ascending"/>
</xsl:applye-templates>
<xsl:template>


<xsl:template match="News"/>
<H1><xsl:value-of select="P1"/></H1>
<!-- Other such stuff here (such as telling which date the news are from -->
</xsl:template>



I can also group by Date using following (taken from XSLT programmers reference 2.0 p.622ff):


<xsl:template match="/">
 <xsl:call-template name="group-by-date"/>
</xsl:template>

<xsl:template name="group-by-date">
<xsl:variable name="unique-dates" select="/NewsList/List/News[not(Date=preceding-sibling::News/Date)]/Date"/>
<xsl:for-each select="$unique-dates">
Date is: <xsl:value-of select="."/><br/>
<xsl:for-each select="/NewsList/List/News[Date=current()]">
<H1><xsl:value-of select="P1"/></H1>
<!-- Other such stuff here, but I would like to put this functionality into another template -->
</xsl:for-each>
</xsl:for-each>
</xsl:template>



Problem with the second stylesheet is that while the result is grouped by date, it is grouped by how the dates appear in document order, which I have no controll over, and I want it by date descending like in the first stylesheet.


If some of you can tell me how to do it, I will be very gratefull.

Sincerly
Ragulf Pickaxe :)


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx



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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.