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

Re: [xsl] summing up incrementally


Subject: Re: [xsl] summing up incrementally
From: Paul Tremblay <phthenry@xxxxxxxxxxxxx>
Date: Thu, 18 Dec 2003 17:52:32 -0500

On Thu, Dec 18, 2003 at 01:41:32PM -0500, cknell@xxxxxxxxxx wrote:
> 
> Where's the summing? Please tell us your method of computing the values to be placed in the output tree element's "percentage-increase" attributes.
> -- 

I need to use the date to create a data showing how much the growth has
increased each year.

The first year (1937) increases only 103 percent from the previous year.

The next year (1938)shows an increase of 102 percent from 1937. But
cumalitively it shows an increase of 105 percent: 103 + 102 = 105.

The next year (1939)  shows an increae of 108 percent. Cumulatively,
this is 113: 103 + 102 + 108 = 113.

WOOPS! 

Of course, 103 + 102 + 108 = 313! 

Okay, I need to minus the 100:

1938 = 03 + 02 = 05

1939 = 03 + 02 + 08 = 13

So what I need to do is add all the previous months of December to the
current month of December:


<root>
<!--result tree-->

<year year = "1937" percentage-increase = "03"/>
 
<!--now add up Decmber 1937 and December 1938-->
<year year = "1938" percentage-increase = "05"/>
 
 
<!--now add up Decmber 1937, December 1938, and December 1939-->
<year year = "1938" percentage-increase = "13"/>
 
 </root>


In other words, how can I say "look in all the previous years, find the
month of December, find the  attribute percent increase, subtract 100,
and add it to the current attribute increase-percent after you subtract
that from 100.

<xsl:template match = "month[@month = 'December']">

<xsl:variable name = "this-month">
<xsl:value-of select = "@percent-increase" - 100"/>
</xsl:variable>

<!--I now have something like $this-month = 03. If the year is 1939, I
need to go back to December of 1937 and 1938 and add how much increase
these years had -->

</xsl:template>


> Charles Knell
> cknell@xxxxxxxxxx - email
> 
> 
> 
> -----Original Message-----
> From:     Paul Tremblay <phthenry@xxxxxxxxxxxxx>
> Sent:     Thu, 18 Dec 2003 13:03:52 -0500
> To:       xsl-list <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> Subject:  [xsl] summing up incrementally
> 
> Is there a way to sum up incrementally?
> 
> My source tree looks something like this:
> 
> <root>
> 
> <year year = "1937">
> 
>   <month month = "January" percentage-increase = "105"/>
>   <!--and so on for each month-->
>   <month month = "December" percentage-increase = "103"/>
> </year>
> 
> <year year = "1938">
>   <month month = "January" percentage-increase = "104"/>
>   <!--and so on for each month-->
>   <month month = "December" percentage-increase = "102"/>
> </year>
> 
> 
> <year year = "1939">
>   <month month = "January" percentage-increase = "106"/>
>   <!--and so on for each month-->
>   <month month = "December" percentage-increase = "108"/>
> </year>
> 
> </root>
> 
> I need to sum up the percentage-increase just for December. I want my
> resulting tree to look like this:
> 
> <root>
> 
> <year year = "1937" percentage-increase = "103"/>
> 
> <!--now add up Decmber 1937 and December 1938-->
> <year year = "1938" percentage-increase = "105"/>
> 
> 
> <!--now add up Decmber 1937, December 1938, and December 1939-->
> <year year = "1938" percentage-increase = "113"/>
> 
> </root>
> 
> I'm thinking I can do with is a recursive template, but can't figure out
> how.
> 
> Thanks
> 
> Paul
> 
> -- 
> 
> ************************
> *Paul Tremblay         *
> *phthenry@xxxxxxxxxxxxx*
> ************************
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

-- 

************************
*Paul Tremblay         *
*phthenry@xxxxxxxxxxxxx*
************************

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread