Subject: Re: [xsl] patial sums From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Fri, 12 Apr 2002 09:34:31 +0100 |
Hi Vrajitoru, > and in the following XSL I want to display partial sums on the > attribute "Valoare" after each grouping. I am new in XML and I tried > everything I knew but it doesn't work. It is possible? and if yes, > how? You just need to sum the value of the @Valoare attribute on the row elements that you're grouping at each level. For example, to sum all the rows with the same Document as the current node, you can use: sum(key('kgrp1', @Document)/../@Valoare) A lot of your paths would be simpler if, instead of matching the attributes themselves, you matched the rows. You're also defining more keys than you need to, effectively duplicating each one. Try this alternative pattern: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:key name="kgrp1" match="row" use="@Document" /> <xsl:key name="kgrp2" match="row" use="concat(@Cod, '::', @Document)" /> <xsl:key name="kgrp3" match="row" use="concat(@Data, '::', @Cod, '::', @Document)" /> <xsl:key name="kgrp4" match="row" use="concat(@Furnizor, '::', @Data, '::', @Cod, '::', @Document)" /> <xsl:template match="/"> <table border="0" width="100%"> <xsl:for-each select="/data/row[generate-id() = generate-id(key('kgrp1', @Document)[1])]"> <xsl:sort select="@Document" order="ascending"/> <xsl:variable name="valgrp1" select="@Document"/> <!-- create a variable to hold the group --> <xsl:variable name="grp1" select="key('kgrp1', @Document)" /> <tr><td> <h2><xsl:value-of select="$valgrp1"/></h2> <!-- show the sum for the group --> <p>Sum: <xsl:value-of select="sum($grp1/@Valoare)" /></p> <table border="0" width="100%"> <xsl:for-each select="$grp1[generate-id(.)= generate-id(key('kgrp2', concat(@Cod,'::',$valgrp1))[1])]"> <xsl:sort select="@Cod"/> <tr><td> <xsl:variable name="valgrp2" select="@Cod"/> <!-- create a variable to hold the group --> <xsl:variable name="grp2" select="key('kgrp2', concat(@Cod, '::', $valgrp1))" /> <h3><br /> <xsl:value-of select="$valgrp2"/> - <xsl:value-of select="@Denumire"/></h3> <!-- show the sum for the group --> <p>Sum: <xsl:value-of select="sum($grp2/@Valoare)" /> ... and so on ... </td></tr> </xsl:for-each> </table> </td></tr> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet> Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] patial sums, Matt Gushee | Thread | [xsl] XSLT Processing Model Questio, Dietrich Ayala |
RE: Business logic (was: Re: [xsl] , Michael Kay | Date | RE: [xsl] Netscape XSLT ?, Michael Kay |
Month |