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 75120 invoked from network); 17 Mar 2000 21:50:05 -0000 Received: from lotus.lotus.com (192.233.136.1) by locus.apache.org with SMTP; 17 Mar 2000 21:50:05 -0000 Received: from internet2.lotus.com (internet2 [9.95.4.236]) by lotus.lotus.com (8.9.3/8.9.3) with ESMTP id QAA17640; Fri, 17 Mar 2000 16:41:22 -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 QAA14113; Fri, 17 Mar 2000 16:49:36 -0500 (EST) Subject: Grouping and Summaries in XSLT To: xalan-dev@xml.apache.org Cc: cocoon-dev@xml.apache.org X-Mailer: Lotus Notes Release 5.0 March 30, 1999 Message-ID: Date: Fri, 17 Mar 2000 16:48:04 -0500 X-MIMETrack: Serialize by Router on CAMMAIL04/CAM/M/Lotus(Release 5.0.2c |February 2, 2000) at 03/17/2000 04:46:52 PM MIME-Version: 1.0 Content-type: text/plain; charset=us-ascii X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N Over time I've been asked a lot about how to do grouping and summaries in XSLT, and this came up the other day again, and I thought I would share the results. This is better a subject for the xsl list, but I thought it would be useful to post it to the xalan list and the cocoon list. You can do anything with XSLT, if you're warped enough. That said, XSLT is not particularly good at grouping at this time (this is one of the things that will go into XSLT V2). 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...) 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:
And a stylsheet: will give you: -scott