xsl-list
[Top] [All Lists]

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

2002-11-13 02:16:56
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



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