473,382 Members | 1,665 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

XSL calculation

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
se**@autip.de
Jul 20 '05 #1
3 3351
> 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:otherwise>
<xsl:value-of select="@AttB + @AttC"/>
</xsl:otherwise>
</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>

</xsl:stylesheet>

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,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #2
"Joris Gillis" <ro**@pandora.be> wrote in message news:<op**************@news.pandora.be>...
[ A very good solution ]


Thank you very much, your solution solved my problem.

Regards,
sebastian
Jul 20 '05 #3
On 3 Nov 2004 12:30:12 -0800, se*@gunis.de (Sebastian Gunreben) wrote:
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
se**@autip.de

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
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Aspersion | last post by:
I'm building an ASP page that has a lot of text and graphics. There is a calculation facility on the page. The user enters several numbers in a form and presses a button to see the calculated...
0
by: anaxamandr | last post by:
Hi. I have a long loop in ASP that performs a rather lengthy calculation. I would love for my users to be able to stop that calculation, if they so choose, mid way through the process. I attempted...
2
by: Del | last post by:
Thanks in advance for any help. I have a database that was created in Access 2000. Several users have been upgraded to Access 2003. Since upgrading to 2003 we have noticed that some of the...
1
by: cdelaney | last post by:
I have a form that I created a calculation on using 2003. The calculation works exactly like I want it to but ONLY on the first and last record. The calculation does not work/exist on records in...
0
by: gavo | last post by:
Hi. using A2K; i have a form containing a continous subform. The question is, how can i call a calculation for one of the fields in the continous subform from the main form. At the moment i...
4
by: Michiel Alsters | last post by:
Hello everybody, I hope anybody can help me. I'll try to give a brief overview of my problem. I have running a program that performs a heavy calculation. To give the user feedback what the...
4
by: vg-mail | last post by:
Hello all, I have identical design for form and report but I am getting calculation error on form and everything is OK on report. The form and report are build up on SQL statement. The...
5
by: The alMIGHTY N | last post by:
Hi all, Let's say I have a simple math formula: sum (x * y / 1000) / (sum z / 1000) I have to do this across 50 items, each with an x, y and z value, when the page first loads AND when a...
3
by: mattmao | last post by:
Okay, I was asked by a friend about the result of this limit: http://bbs.newwise.com/attdata/forumid_14/20070922_fe7f77c81050413a20fbDWYOGm7zeRj3.jpg Not n->zero but n-> + infinite I really...
5
by: =?Utf-8?B?amVsbGU3OQ==?= | last post by:
Hi, I want to use a difficult Excelsheet as source for my calculation in a ASP.NET (C#) page. I have 5 input fields on my ASP.NET page and when I press the submit button I want to put these...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.