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

RE: How to sort and group using n-column table?

Subject: RE: How to sort and group using n-column table?
From: Jarno.Elovirta@xxxxxxxxx
Date: Wed, 13 Nov 2002 11:16:56 +0200
sort by group by
Hi,

> I found out recently how to take a collection of sibling elements and
> place them in an n-column table, using a construct such as the
> following:
> 
>  <xsl:for-each select="element[position() mod 3 = 1]">
>   <tr>
>    <xsl:apply-templates 
> select=".|following-sibling::element[position() &lt; 3]"/>
>   </tr>
>  </xsl:for-each>
> 
>  ...and then a template which includes the <td> tags only for each
>  element.
> 
> This works just fine and can, of course, be adapted to any width.
> 
> What I am having a problem with is to first sort the siblings, then
> place them in the table.  Putting a sort in the for-each is no good as
> it will only sort the "position() mod 3" elements.  Likewise putting a
> sort in the apply-templates only sorts the row.
> 
> I tried creating a variable with the sorted elements by use of a
> for-each declaration with sort inside the variable definition, but
> this gives a result tree fragment and not a node set (as I just found
> out) and therefore I cannot further process it with standard XSL.

exslt:node-set() is quite common, and if you control the environment where the stylesheet is executed, you might want to consider using that.

> I've seen techniques using CDATA to 'sneak' the <TR> and </TR>
> elements in in a procedural fashion using xsl:if constructs, but this
> strikes me as very untidy and 'cheating'.

Yes, you definitely don't want to go there.

> I have looked through the archives of this list and various FAQs and
> none of the examples under 'grouping' or 'tables' seem to cover my
> case - namely that the table is purely a means of saving vertical
> space by placing elements across the page.  In most cases the
> examples' tables have meaning in their rows or columns. And in
> most cases where order is important, the data is already ordered!
> 
> My requirement is more akin to simple 'multi-up' printing.
> 
> Can anyone suggest an approach that uses standard XSL (I'm not sure
> whether my host has any extensions), and preferably not any kludges?

Two chained transformations. First sort the table, then group it.

Jarno - Assemblage 23: Awake (Imperative Reaction Mix - 138 BPM)

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.