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

Re: sorting related issue

Subject: Re: sorting related issue
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 14 Dec 2001 16:50:50 +0000
xsl sort pick first
Hi Sanjay,

> I would like to sort my XML on <name> and <type> on the Client side
> and do things like do not display "name" if the next "ErrorMessage"
> record also has the same "name".
>
> I tried checking using "preceding-sibling" but that uses the
> "document order". I am sure this is a trivial issue, but I need some
> clue / pointers / direction.

It sounds as if you want to group your ErrorMessage elements by name.
Unfortunately, grouping isn't 'trivial' in XSLT. You have to pick out
the first ErrorMessages in the document with each name, sort those by
name, and then for each of them display all the ErrorMessages with the
same name, sorted by type.

As an example, have a look at the following:

<!-- index the ErrorMessage elements by their name child -->
<xsl:key name="errors" match="ErrorMessage" use="name" />

<xsl:template match="ErrorMessages">
  <!-- iterate over the first ErrorMessages with each name -->
  <xsl:for-each
      select="ErrorMessage[generate-id() =
                           generate-id(key('errors', name)[1])]">
    <!-- sort them by name -->
    <xsl:sort select="name" />
    <!-- give the name for the group and create a list -->
    <h2><xsl:value-of select="name" /></h2>
    <ul>
      <!-- iterate over all the ErrorMessages with the same name -->
      <xsl:for-each select="key('errors', name)">
        <!-- sort them by type (which is a number) -->
        <xsl:sort select="type" data-type="number" />
        <!-- give some output about the ErrorMessage -->
        <li>
          <xsl:value-of select="type" />:
          <xsl:apply-templates select="details" />
        </li>
      </xsl:for-each>
    </ul>
  </xsl:for-each>
</xsl:template>

For a more detailed description, see
http://www.jenitennison.com/xslt/grouping/muenchian.html.

I hope that helps,

Jeni

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


 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.