Subject: Re: [xsl] Grouping (yet again) From: "Steve Muench" <Steve.Muench@xxxxxxxxxx> Date: Wed, 20 Feb 2002 15:08:21 +0100 |
If you're ok using Saxon 7.0 (which implements the new grouping functionality of XSLT 2.0), then here's the XSLT 2.0 (draft) solution: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output indent="yes"/> <xsl:template match="/"> <graph> <!-- Group first by @group --> <xsl:for-each-group select="list/datum" group-by="@group"> <data group="{@group}"> <!-- Within group, then group by YYYYWW number (defaults to ascending) --> <xsl:for-each-group select="current-group()" group-by="concat(@year,@week)"> <xsl:sort data-type="number" select="number(concat(@year,@week))"/> <datum week="{concat(@year,@week)}"> <!-- Within week, group by dir, ordering descending by sum of @value --> <xsl:for-each-group select="current-group()" group-by="@dir"> <xsl:sort data-type="number" order="descending" select="sum(current-group()/@value)"/> <datum value="{sum(current-group()/@value)}" dir="{@dir}"/> </xsl:for-each-group> </datum> </xsl:for-each-group> </data> </xsl:for-each-group> </graph> </xsl:template> </xsl:stylesheet> On your data, this produces for me: <?xml version="1.0" encoding="utf-8"?> <graph> <data group="Downloads"> <datum week="200143"> <datum value="350" dir="xerces-j"/> <datum value="115" dir="soap"/> <datum value="87" dir="batik"/> <datum value="81" dir="xerces-c"/> <datum value="74" dir="axis"/> <datum value="72" dir="fop"/> <datum value="39" dir="cocoon2"/> <datum value="38" dir="xalan-j"/> <datum value="36" dir="cocoon"/> <datum value="29" dir="crimson"/> <datum value="8" dir="xerces-p"/> <datum value="3" dir="xalan-c"/> </datum> <datum week="200144"> <datum value="115" dir="soap"/> <datum value="87" dir="batik"/> <datum value="74" dir="axis"/> <datum value="72" dir="fop"/> <datum value="46" dir="cocoon2"/> <datum value="36" dir="cocoon"/> <datum value="29" dir="crimson"/> <datum value="3" dir="xalan-c"/> </datum> </data> <data group="Uploads"> <datum week="200143"> <datum value="91" dir="batik"/> <datum value="74" dir="axis"/> <datum value="29" dir="crimson"/> <datum value="7" dir="cocoon2"/> <datum value="3" dir="cocoon"/> </datum> <datum week="200144"> <datum value="700" dir="xerces-j"/> <datum value="230" dir="soap"/> <datum value="162" dir="xerces-c"/> <datum value="144" dir="fop"/> <datum value="76" dir="xalan-j"/> <datum value="29" dir="crimson"/> <datum value="16" dir="xerces-p"/> <datum value="6" dir="xalan-c"/> </datum> </data> </graph> _____________________________________________________________________ Steve Muench - Developer, Product Manager, XML Evangelist, Author "Simplifying J2EE and EJB Development with BC4J" http://otn.oracle.com/products/jdev/htdocs/j2ee_with_bc4j/j2ee_with_bc4j.html "Building Oracle XML Applications" - www.oreilly.com/catalog/orxmlapp XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Grouping (yet again), G. Ken Holman | Thread | RE: [xsl] Grouping (yet again), Steven Noels |
[xsl] Loosing encoding information, Ragulf Pickaxe | Date | Re: [xsl] Problems with characters, Tony Graham |
Month |