[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] How do I change a XSL style sheet to group data together under one heading


Subject: Re: [xsl] How do I change a XSL style sheet to group data together under one heading
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Fri, 18 May 2007 02:12:39 +0200

kieters c wrote:

Thank you. I copied your code into an xsl file and use it with the flat file. It grouped it all by date. Just one additional question data is grouped by a selection of variables. As you would have noticed in the first example: sample_date_time, cp_name, imis_cp_ext and two other. How do I combine it in the key name instruction?


Incidently this may be the only instance that I may be using it.


if there's no overlap in the values (i.e., when you concatenate them that they create the uniqueness you want), you can do this:


<xsl:key name="sample" match="sample" use="concat(sample_date_time, cp_name)" />

in addition, of course, you also change the key(...) functions throughout with the same as in you the use attribute.

When the values do overlap, you can make them more unique when adding a separator, like in concat(sample_date_time, ':', cp_name). Of course, you can concat as many values as you want. Make sure that the xpaths you provide are correct when seen as relative to the match attribute of the key (in this case, the sample node). And think of moving to XSLT 2.0 as soon as possible if you have more of this kind of problems. You can simply use:

<xsl:for-each-group select="sample" group-by="yourgroupbyclausehere" >....

and many other handy constructs (i.e., you can group by nodes that are separated by a node with a certain value, or that are siblings of one another by some rule etc etc). It's all possible in XSLT 1.0 too, but much harder and not with a single statement. And if you have little XSLT knowledge, it can be very hard.

Please read up on the tutorials as well, you may want to know how it all works: http://www.jenitennison.com/xslt/grouping/muenchian.html

Cheers,
-- Abel Braaksma


Current Thread
Keywords