XSL calculation

  • Thread starter Sebastian Gunreben
  • Start date
S

Sebastian Gunreben

Hi,

I spent quite some weeks seaching google groups for a solution,
but unfortunatly I didn't find anything matching my problem.
Perhaps some of you has an idea ...

My XML file looks as follows:
<Table>
<Row AttA="3" AttB="-2" AttC="2" />
<Row AttA="2" AttB="2" AttC="2" />
<Row AttA="-1" AttB="-2" AttC="6" AttC="3" />
...
</Table>

Each row has an arbitrary number of attributes. On this attributes a
function F(AttA, ..., AttC) calculates a value. The values should be
accumulated in the output. E.g. the function F is defined as:
if( AttA == 3 )
value = AttB * AttC;
else
value = AttB + AttC;

The output should look like:
<table>
<tr><td>-4</td></tr>
<tr><td>0</td></tr> <!-- -4 + 4 -->
<tr><td>4</td></tr><!-- -4 + 4 + 4 -->
</table>

To summarize my problem:
I can calculate each row by itself, dependent of the function F.
But I have some difficulties accumulating the results. Does the
solution depend
on the function F? Have you got any ideas?

Best regards

sebastian gunreben
(e-mail address removed)
 
J

Joris Gillis

My XML file looks as follows:
<Table>
<Row AttA="3" AttB="-2" AttC="2" />
<Row AttA="2" AttB="2" AttC="2" />
<Row AttA="-1" AttB="-2" AttC="6" AttC="3" />
...
</Table>

Each row has an arbitrary number of attributes. On this attributes a
function F(AttA, ..., AttC) calculates a value. The values should be
accumulated in the output. E.g. the function F is defined as:
if( AttA == 3 )
value = AttB * AttC;
else
value = AttB + AttC;

The output should look like:
<table>
<tr><td>-4</td></tr>
<tr><td>0</td></tr> <!-- -4 + 4 -->
<tr><td>4</td></tr><!-- -4 + 4 + 4 -->
</table>
Hi,

You could use something like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="Row[1]">
<table>
<xsl:call-template name="F"/>
</table>
</xsl:template>

<xsl:template name="F">
<xsl:param name="Subtotal" select="0"/>

<xsl:variable name="fv">
<xsl:choose>
<xsl:when test="@atta = 3">
<xsl:value-of select="@AttB * @AttC"/>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="@AttB + @AttC"/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:variable>

<tr><td><xsl:value-of select="$fv + $Subtotal"/></td></tr>

<xsl:for-each select="following-sibling::*[position()=1]">
<xsl:call-template name="F">
<xsl:with-param name="Subtotal" select="$Subtotal + $fv"/>
</xsl:call-template>
</xsl:for-each>

</xsl:template>

Does the solution depend on the function F?

Not in my sample xslt: you can adapt the function F without problem by modifying the code inside the 'xsl:variable' tag

regards,
 
J

Jeff Kish

Hi,

I spent quite some weeks seaching google groups for a solution,
but unfortunatly I didn't find anything matching my problem.
Perhaps some of you has an idea ...

My XML file looks as follows:
<Table>
<Row AttA="3" AttB="-2" AttC="2" />
<Row AttA="2" AttB="2" AttC="2" />
<Row AttA="-1" AttB="-2" AttC="6" AttC="3" />
...
</Table>

Each row has an arbitrary number of attributes. On this attributes a
function F(AttA, ..., AttC) calculates a value. The values should be
accumulated in the output. E.g. the function F is defined as:
if( AttA == 3 )
value = AttB * AttC;
else
value = AttB + AttC;

The output should look like:
<table>
<tr><td>-4</td></tr>
<tr><td>0</td></tr> <!-- -4 + 4 -->
<tr><td>4</td></tr><!-- -4 + 4 + 4 -->
</table>

To summarize my problem:
I can calculate each row by itself, dependent of the function F.
But I have some difficulties accumulating the results. Does the
solution depend
on the function F? Have you got any ideas?

Best regards

sebastian gunreben
(e-mail address removed)
Hi.

What situation are you in as far as environment and technology.. what are your
restrictions? Can you use a command line solution, a java class solution or
what?
Jeff Kish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,833
Latest member
BettyeMacf

Latest Threads

Top