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

RE: Yet Another Sorting Problem

Subject: RE: Yet Another Sorting Problem
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Wed, 28 Jul 2004 16:59:30 +0100
sort in data structure
This is yet another problem that's easy in XSLT 2.0 but quite hard in 1.0.

In 2.0 you can calculate the sort key by calling a stylesheet function, or
by instructions inside the xsl:sort element:

<xsl:sort>
  <xsl:for-each ...
  </xsl:for-each>
</xsl:sort>

In 1.0 it's probably simplest to calculate the sort key in a first pass,
storing it as an attribute on the temporary tree, then do the sorting in a
second pass.

Michael Kay 

> -----Original Message-----
> From: Allin Cottrell [mailto:cottrell@xxxxxxx] 
> Sent: 28 July 2004 16:17
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Yet Another Sorting Problem
> 
> I've consulted the FAQ, but I'm having difficulty 
> extrapolating to the 
> answer to this one.
> 
> In sorting a bibliography, I want to sort the elements (e.g. books, 
> articles) by author's name and publication date.  OK, that's easy. 
> My problem is handling multiple authors, with the the number unknown 
> in advance.  For flexibility in formatting the authors' names I can't 
> have them all in one big string; the data-structure I 
> actually have is 
> this:
> 
> * each bibliography-entry element has an "authorlist" element.
> * an authorlist has one or more "author" elements, which have
>    attributes such as surname, fist name, initials.
> 
> The easy solution, if it were available, would be to wrap the 
> xsl:sort 
> selection code in an xsl:for-each ranging across the authors in an 
> entry's authorlist, but that's forbidden by xsl syntax.
> 
> Next thought: construct on the fly a "grand author string" by lumping 
> together the names and initials of all the authors in an entry's 
> authorlist, and use this as the sort key for the entries.
> 
> Seems promising, but I haven't managed to implement it.  What I have 
> so far is broken -- I realize I can't use xsl:attribute to do this, 
> but I'm not sure what I should be using.
> 
> <xsl:template match="bibliography">
>    <xsl:for-each select="book|journalarticle|paper">
>      <xsl:attribute name="auhash">
>        <xsl:for-each select="authorlist/author">
>          <xsl:value-of select="@surname"/>
>          <xsl:value-of select="@initials"/>
>        </xsl:for-each>
>      </xsl:attribute>
>    </xsl:for-each>
>    <xsl:apply-templates select="book|journalarticle|paper">
>      <xsl:sort select="@auhash"/>
>      <xsl:sort select="pubdate"/>
>    </xsl:apply-templates>
> </xsl:template>
> 
> -- 
> Allin Cottrell
> Department of Economics
> Wake Forest University, NC

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.