473,385 Members | 1,814 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,385 software developers and data experts.

Straightforward way to sum calculated values across multiple parents?

<store>
<frequent_shopper_discount value="5"/>
<premium_member_discount value="10"/>
<inventory>
<item>
<msrp value="3.99"/>
</item>
<item>
<msrp value="2.78"/>
</item>
<item>
<msrp value="16.24"/>
</item>
<item>
<msrp value="9.66"/>
</item>
<item>
<msrp value="4.53"/>
</item>
</inventory>
</store>

Is there a straightforward way to calculate the sum of these item's
MSRP values rounded at the item level? By this I mean to apply the 15%
discount on each of the individual MSRPs before summing them?

Right now, my report is outputting a row for each of the individual
items in the inventory. I do this in a template that matches the store
element by iterating through inventory/item and applying the round
function as follows:

round(msrp/@value * 100 * (1 -
(number(../../frequent_shopper_discount/@value) div 100)) * (1 -
(number(../../premium_member_discount/@value) div 100)))

I'm looking for a straightforward way to do this without having to
change the XML structure because any changes would require the Java
development staff to invest time that they do not have right now.

Thanks in advance for any help you can give.

Regards,

Nathaniel

Jan 18 '07 #1
1 1712
Tempore 17:12:06, die Thursday 18 January 2007 AD, hinc in foro {comp.text.xml} scripsit The alMIGHTY N <na******@yahoo.com>:
<store>
<frequent_shopper_discount value="5"/>
<premium_member_discount value="10"/>
<inventory>
<item>
<msrp value="3.99"/>
</item>
<item>
<msrp value="2.78"/>
</item>
<item>
<msrp value="16.24"/>
</item>
<item>
<msrp value="9.66"/>
</item>
<item>
<msrp value="4.53"/>
</item>
</inventory>
</store>

Is there a straightforward way to calculate the sum of these item's
MSRP values rounded at the item level? By this I mean to apply the 15%
discount on each of the individual MSRPs before summing them?
Hi,
In XSLT2, this is a trivial task:

sum(for $item in inventory return round(msrp/@value ...))

In XSLT1, however it's a bit trickier. You might try to tackle it using recursion. For example:

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

<xsl:output indent="yes"/>

<xsl:template match="inventory">
<!-- Start summing with the first item-->
<xsl:apply-templates select="item[1]" mode="sumDiscount"/>
</xsl:template>

<xsl:template match="item" mode="sumDiscount">
<xsl:param name="runningSum" select="0"/>

<xsl:variable name="updatedSum" select="$runningSum + round(msrp/@value * 100 * (1 -
(number(../../frequent_shopper_discount/@value) div 100)) * (1 -
(number(../../premium_member_discount/@value) div 100))) div 100"/>

<!-- Proceed summing with the next item-->
<xsl:apply-templates select="following-sibling::item[1]" mode="sumDiscount">
<xsl:with-param name="runningSum" select="$updatedSum"/>
</xsl:apply-templates>

<!-- No more items. Summing is complete-->
<xsl:if test="not(following-sibling::item)">
<xsl:value-of select="$updatedSum"/>
</xsl:if>

</xsl:template>

</xsl:stylesheet>

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
«Quot capita, tot sententiae» - Terentius , Phormio 454
Feb 9 '07 #2

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

Similar topics

1
by: SJH | last post by:
I have been given an older database and asked to make upgrades and what not. One interesting thing I have come across with the database is that it was at one time set up so one of the tables would...
0
by: Henry | last post by:
Hi Is there any good ideas how to update form vb code always after some values are changed / added by vb (not user). I have some code behind subforms vb and there are calculations behind...
4
by: Abbey Krystowiak | last post by:
Does anyone know if I can have a field in a row where I can add two lines of info without adding a whole new line? and then there would be a drop down menu? *** Sent via Developersdex...
3
by: Hazz | last post by:
I am just beginning to design a Treeview display (winforms) for wine regions. Problem. Some wine growing regions belong to two counties. Eg. Carneros is in both Napa and Sonoma Counties. Although...
3
by: mkjets | last post by:
I have worked for hours on trying to find a solution and have not figured it out. I am working in Access 2003. I need to create a query that takes values from 1 table and displays them in...
9
by: Mohd Al Junaibi | last post by:
Hello all, my first post here...hope it goes well. I'm currently working on stored procedure where I translated some reporting language into T-SQL The logic: I have a group of tables...
8
by: Kasghost | last post by:
It seems like this should have been easy to do but a solution is just eluding me. Here is my situation, I am working on an Access DB for a class project, my instructor wanted me to create a form...
3
by: Andrew Meador | last post by:
I have searched and found where this has been discussed, but the suggestions I have found have all ended up tuning into debated about whether it needs to be done - but - as far as I can tell - I...
24
by: NaftoliGug | last post by:
Is there a way to have unbound, uncalculated controls (or a calculated control that is based on a function) that retains a different value for each record?
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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.