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

Re: Text Table with sorting

Subject: Re: Text Table with sorting
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 25 Sep 2003 17:39:33 +0100
xsl get items sorted list
Hi Ryan,

> I have accomplished this by first figuring out what column has the
> most entries (in the example below this would be maritalStatus).
> Then I do a for-each on that column, and print out each entry by
> indexing the three node-sets. The problem is, since I am doing only
> one for-each loop I can't seem to sort multiple columns.

This is a tough problem. To be honest, I'd approach it using two
steps: one to do the sorting and the other to arrange the columns. In
other words, create an intermediate representation like:

    <maritalStatus refDate="1997-01-15">marriage</maritalStatus>
    <religion refDate="1996-12-02">Lutheran</religion>
    <maritalStatus refDate="1993-06-24">divorce</maritalStatus>
    <maritalStatus refDate="1989-04-11">marriage</maritalStatus>
    <religion refDate="1968-04-05">Roman Catholic</religion>

(which is simply a matter of sorting by @refDate), and then to your
desired output, using your current method of indexing into the three
node-sets of <maritalStatus>, <religion> and <dateOfBirth> elements.

An alternative, one-pass solution, is to use a template to get the
element in a particular (sorted) position; something like:

<xsl:template name="get-item-in-sorted-list">
  <xsl:param name="list" select="/.." />
  <xsl:param name="index" />
  <xsl:for-each select="$list">
    <xsl:sort select="@refDate" />
    <xsl:if test="position() = $index">
      <xsl:apply-templates select="." />

Then, rather than:

>     <xsl:call-template name="print-entry">
>        <xsl:with-param name="entry" select="$left[ $for-each-pos ]"/>
>     </xsl:call-template>

use something like:

  <xsl:call-template name="print-entry">
    <xsl:with-param name="entry">
      <xsl:call-template name="get-item-in-sorted-list">
        <xsl:with-param name="list" select="$left" />
        <xsl:with-param name="index" select="$for-each-pos" />

By the way, if you can switch to XSLT 2.0 (using Saxon 7.6.5), this
becomes a lot easier...



Jeni Tennison

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

Current Thread


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.
First Name
Last Name
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.