cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Hunsberger <peter.hunsber...@gmail.com>
Subject Re: [GSoC] status reports?
Date Tue, 23 Aug 2005 14:04:55 GMT
On 8/22/05, Robert Graham <intrect@gmail.com> wrote:

<snip/>

> The ordering issues are fairly simple to describe. I can't make XSLT
> do what I want. Most likely because I'm not too familiar with it. I
> have snippets (many of them) in a file with attributes of key, type,
> and name. I'd like to order them by type first which I've done. The
> snippets that have the same name attribute, however, are related to
> each other and should be ordered adjacent to each other. I can't see
> how to get each (<snippet name="XXX">) with the same name attribute to
> stick together without knowing the name attributes I'm interested in
> beforehand. (look at ordering-neutral.xsl)

I'm also notablet to look at the code at the moment, but there are
likely two possibilities here.

First, as Helma points out, you can add a second sort instruction:

<xsl:for-each select="//snippet">
   <xsl:sort select="@type"/>
   <xsl:sort select="@name"/>

I do not believe doing a sort select="@*" will work.  

In some cases I end up constructing the select statement on the fly
and using  eval extension to turn it into proper sort order.  Eg:

<xsl:variable name="sortcmd">some complicated logic...</xsl:variable>
<xsl:for-each select="//snippet">..
    <xsl:sort select="exslt:eval($sortcmd)" .../>

Obviously that's not optimum since it isn't completely portable, but
it is powerful.  In particular, you can build look up tables that tell
you how to sort on various types, index into them, and build your
resultant sort.

The second possibility is that you really have a grouping problem and
that you want to group first, then sort on the grouped results.  There
are all kinds of resources on XSLT grouping; the Mulberry XSLT list
has dozens of FAQ's and archived mailings on it (some from me asking
strange grouping questions). If you think this approach may be more
fruitful you can ask more here or there...

-- 
Peter Hunsberger

Mime
View raw message