I'm trying to calculate a sum of a table column in a xsl-fo file.

I iterate over a all cartoon characters found in an xml file and calculate a value of earned points for each character named "goofy".

To select the goofy-character I'm using a an if-clause within a for-each loop (see below). (I know that this could be done more elegant with an XPATH expression for this simple example).

What I need to get done, is to sum up all values that are outputed to the fo-file. Essentially I want to do something like this (perl-like code).

my $sum=0;
my $pointrate = 2.0;
foreach $dog @dogs
{
if ($dog{'name'} == 'goofy')
{
$sum += $constants{'dog'} / $pointrate;
}
}


XSL-Code
---------------------------------------------------------------------
<!-- body -->
<fo:table-body>
<xsl:for-each select="/comic/character[@race='dog']">
<xsl:if test="@name='goofy'">
<xsl:variable name="earnedPoints" select="/dogs/constants/points div sum(//pointrate)"/>
<fo:table-cell border="solid black 1px" padding="2pt">
<fo:block><xsl:value-of select="$earnedPoints"/></fo:block>
</fo:table-cell>
<fo:table-cell border="solid black 1px">
<fo:block font-weight="bold">some value</fo:block>
</fo:table-cell>

</xsl:if>
</xsl:for-each>
</fo:table-body>
-----------------------------------------------------------------------

Since variables can't change their value in XSLT I don't know how to do the sum += $constants{'dog'} / $pointrate; in XSLT.


I understand french, but not fit to express myself in french.

Thanks for help

Tschuri
Administrateur
Hello Tschuri and welcome here,

I hope for you that a few members could help you.

Could you please read the forum Rules one more time and use the [ CODE] tags in order to make your samples more readable ?
Thank you.
Modifié par Raphael (02 May 2005 - 16:42)