[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Calculating cumulative values - another call for help


Subject: Re: [xsl] Calculating cumulative values - another call for help
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Wed, 29 Aug 2007 09:40:00 +0100

On 8/29/07, Simon Shutter <simon@xxxxxxxxxxx> wrote:
> Dear Experts,
>
> I've been aggregating numbers in XSLT 1.0 using the preceding-sibling:: axis
> for nodes with the same parent.  I now need to aggregate all the values that
> precede the context node, even if they have different parents.  For this I
> added another attribute using the preceding:: axis (see XSLT 1.0 Stylesheet
> below).  Unfortunately, the transform is starting to groan under the weight
> of all these O(n^2) operations.  I have revisited an earlier solution
> suggested by Dimitre Novatchev (see XSLT 2.0 Stylesheet below) that uses
> FXSL.  However, I'm not clear how I can adapt it to meet the new
> requirements.  Specifically, I would like to:
>
> a) generate attribute y3 that is a cumulative value based on all preceding
> <point> elements
> b) copy y1 from the input to the output

- If you can use XSLT 2.0 then just do it in two passes
- If you are stuck with 1.0 without the node-set extension then you
could optimize it a little by processing <point> elements along the
following-sibling axis passing the running total as you go (but that
would require @x to have a limited number of possible values)
- If you are using 1.0 + node-set extension then again just do two
passes to avoid O(n^2)

cheers
andrew
-- 
http://andrewjwelch.com


Current Thread
Keywords