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

Sort list by a combination of elements

Subject: Sort list by a combination of elements
From: Manuel Strehl <manuel.strehl@xxxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 21 Dec 2006 14:28:03 +0100
combination of elements
Hi.

Consider some kind of bookshelf XML:

<bookshelf>
    <series id="LoTR">
       <author>Tolkien</author>
    </series>
    ...
    <book>
       <title>Two Towers</title>
       <belongs_to ref="LoTR">
    </book>
    ...
    <book>
       <title>It</title>
       <author>King</author>
    </book>
</bookshelf>

So we have <book>s with <author> elements and <book>s with a
<belongs_to> referring to a series of some author.

Problem: Sort the list of books by the author.

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.

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:

<choose>
    <when test="author"><sort select="author">
    <otherwise><sort select="series/author">
</choose>

Best Regards
Manuel

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.