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

Re: Sort list by a combination of elements

Subject: Re: Sort list by a combination of elements
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 21 Dec 2006 13:42:14 GMT
sort select list
> Solution: Normally one would write something like <xsl:sort
> select="//book/author" />. In this case, I found a solution by
> concatenating: <xsl:sort select="concat( //book/author, //series[ @id =
> current()/belongs_to/@ref ]/author )" />. This works, BUT it "feels like
> a hack", if you know, what I mean.

in both cases you wouldn't want to start the xpaths with // otherwise
all elements would get the same sort key (as these are absolute paths
not depending on the element being sorted)


> I would prefer a more XSLT-like solution, that determines, if there is
> an <author> element, sorts by this and uses the <series> author as a
> fallback. Does anyone know, if and how this could be done? Schematically:

in xslt2
<xsl:key name="series" match="series" use="@id"/>
...

<xsl:for-each select="book">
<xsl:sort select="(author,key('series',belongs_to_ref)/author)[1]"/>

in xslt1

<xsl:key name="series" match="series" use="@id"/>
...

<xsl:for-each select="book">
<xsl:sort select="(author|key('series',belongs_to_ref)/author)[last()]"/>

The xslt2 version does exactly what you ask, thehe xslt 1 version has
the additional restriction (that could be removed) that if a book has
both an author and a series ref, that the series element appears before
the book in document order.

David

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.