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

Re: Sorting under for-each-group

Subject: Re: Sorting under for-each-group
From: "andrew welch" <andrew.j.welch@xxxxxxxxx>
Date: Tue, 8 Aug 2006 15:03:17 +0100
for each group sort
On 8/8/06, Mark Wilson <drmark@xxxxxxxxxxxxxxx> wrote:
The Stylesheet below does most of what I want -- It groups all of the
entries for a single Subject under a single subject heading. I would like
to
subsort under each group (Subject) first by author then by title, and if
possible, when there is/are no author/authors, by title alone. The example
would put the Kolar book first, then the Siegar Book, both under the single
heading "Catalogs. Austria".

I have spent a lot of time on it but have not been able to solve the sort
within groupings problem. Can someone help?
stylesheet and xml input sample below

Thanks,
Mark

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:template match="/">
    <List>
        <xsl:for-each-group select="/List/Entry" group-by="Subject">
        <Entry>
            <xsl:copy-of select="Subject"/>
            <xsl:for-each select="current-group()">
                <Item>
                <xsl:copy-of select="*[not(self::Subject)]"/>
                </Item>
            </xsl:for-each>
            </Entry>
        </xsl:for-each-group>
    </List>
</xsl:template>
</xsl:stylesheet>

--------------------------------
- <List>
    - <Entry>
          <Subject>Catalogs. Austria</Subject>
          <Author>Sieger, Hermann Walter</Author>
        - <Book>
              <Title>Zeppelinpost spezial-katalog</Title>
          </Book>
    -  </Entry>
    - <Entry>
      <Subject>Catalogs. Austria</Subject>
      <Author>Kolar, Hugo</Author>
    - <Book>
          <Title>Katalog znamok Rakzsko 1850-1918</Title>
      <Edition>Second</Edition>
      </Book>
      </Locator>
  </Entry>
</List>

Add a couple of xsl:sort's to your for-each:


<xsl:for-each select="current-group()">
 <xsl:sort select="Author"/>
 <xsl:sort select="Book/Title"/>

This will sort by Author first, then by Book/Title.  If no Author is
present it will just sort by Book/Title.

cheers
andrew

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-2011 All Rights Reserved.