This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Re: patial sums
- From: Dimitre Novatchev <dnovatchev at yahoo dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Fri, 12 Apr 2002 00:50:23 -0700 (PDT)
- Subject: [xsl] Re: Re: patial sums
- Reply-to: xsl-list at lists dot mulberrytech dot com
Matt Gushee <mgushee at havenrock dot com> wrote:
> > I have an XML like this:
> >
> > <?xml version='1.0' ?>
> > <?xml-stylesheet type='text/xsl' href='raport.xsl'?><data>
> > <row Cod='212' Denumire='VINZARI CATRE ALTE UNITATI'
> > Document='FACTURA'
> > Numar='12358' Data='2000-10-19' Furnizor='32802' Comanda='X'
> > Valoare='757900.0'/>
> > ....
> > </data>
> >
> > 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?
>
> Boy, that is some dangerous-looking XSLT you've got there, sir ;-)
>
> But the answer to your question is, yes. Here's a drastically
> simplified example of one technique that will work:
>
> <xsl:for-each select="row">
> <xsl:value-of select="sum(@Valoare|preceding-
> sibling::*/@Valoare)"/>
> </xsl:for-each>
>
> In other words, each time a row is processed, output the sum of the
> current row's Valoare attribute and the Valoare attributes of all
> previous rows. I think that's what you need, isn't it?
This has an O(N^2) complexity because the same sums are re-calculated
all over again and again.
For a linear solution for obtaining incremental results over a list
(e.g. running totals, etc.) do have a look at the functions scanl() and
scanl1() from the FXSL functional programming library. they are located
in the file scanl.xsl
Hope this helped.
Cheers,
Dimitre Novatchev.
__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list