Return-Path: Mailing-List: contact cocoon-dev-help@xml.apache.org; run by ezmlm Delivered-To: mailing list cocoon-dev@xml.apache.org Received: (qmail 28797 invoked from network); 17 Mar 2000 23:55:47 -0000 Received: from lotus2.lotus.com (192.233.136.8) by locus.apache.org with SMTP; 17 Mar 2000 23:55:47 -0000 Received: from internet2.lotus.com (internet2 [9.95.4.236]) by lotus2.lotus.com (8.9.3/8.9.3) with ESMTP id TAA00349; Fri, 17 Mar 2000 19:11:49 -0500 (EST) From: Scott_Boag@lotus.com Received: from cammail04.lotus.com (CAMMAIL04.lotus.com [9.95.4.116]) by internet2.lotus.com (8.9.3/8.9.3) with ESMTP id SAA22135; Fri, 17 Mar 2000 18:55:19 -0500 (EST) Subject: Re: Grouping and Summaries in XSLT To: cocoon-dev@xml.apache.org Cc: xalan-dev@xml.apache.org X-Mailer: Lotus Notes Release 5.0 March 30, 1999 Message-ID: Date: Fri, 17 Mar 2000 18:53:33 -0500 X-MIMETrack: Serialize by Router on CAMMAIL04/CAM/M/Lotus(Release 5.0.2c |February 2, 2000) at 03/17/2000 06:52:34 PM MIME-Version: 1.0 Content-type: text/plain; charset=us-ascii X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N Cool! I was thinking that not(fqhn/@Value = previous-sibling::ROW/fqhn/@Value)wouldn't do the trick, for some strange reason, but it seems to do fine. You should also be able to do not(fqhn/@Value = following-sibling::ROW/fqhn/@Value), which would match the last occurance, instead of the first, which would be slightly faster, since both XT and Xalan tend to be slower with previous-sibling. Thanks for the insight. -scott John Prevost cc: cocoon-dev@xml.apache.org, (bcc: Scott Boag/CAM/Lotus) Sent by: Subject: Re: Grouping and Summaries in XSLT prevost@isil.l ocaldomain 03/17/00 06:33 PM Please respond to cocoon-dev Scott_Boag@lotus.com writes: > The only technique I know of to group without knowing the selection > criteria of the groups ahead of time, is to recurse into a named template > for each element passing in a string, add the found selection criteria to > the string via the concat function, and then test with the contains() > function if the selection criteria exists withing the string. It's ugly > and a bit slow, but it works. (This would be easy if you had for loops and > assignable variables in XSLT, but such is the design constraints of the > language...) There's a much much much easier way to do this. It's a little odd to the imperative-language trained mind, but it grows on you. (Like a fungus.) Key idea: find a set of nodes which contains one item for each "group" you want. The item should allow you to get the group it's associated with. The easiest choice is usually "the first node in the group", which translates (when you're working with non pre-determined groups) to "every node for which no previous node has the same 'grouping property'".) I've done this with your example below: > In the sample below, the user wanted to group the rows by server, and then > provide summaries for each month's memory consumption. The transformation > is a useful example of how to do two-level grouping using the above > technique. It would be nice to paramiterise the templates and simply put > them in a library, but that would be difficult, I think. I'm sure the > named templates could be improved in a couple of ways for better > performance. I'll be interested to see what ideas folks come up with. > BTW, you could also use extensions to do this, but the transformation below > is totally interoperable. > > The input data: > > > > > > > > > > > > > > > > > > > > > >
> will give you: > > > > > > > > > > > > > Mine too. (I tested it with Xalan and Cocoon while writing this mail.) This can also be used to, in a really heinous way, do things like turn data organized in "columns" at the top level into data organized in "rows" (suitable for use in HTML.) That is: 1A 1B 2A 2B 2C becomes 1A 2A 1B 2B 2C or vice-versa. (I'll be happy to share the code with people if they think their sanity will survive it. I'll give you a hint: the first step is to find the longest row.) In any case--this needs to be fixed some day. Neither Scott's method or mine is terribly appealing to the well-balanced soul. John.