xsl-list
[Top] [All Lists]

[xsl] Sort list by a combination of elements

2006-12-21 06:28:24
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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>