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

Summary of Unique Records in XML

I can create a list of unique items and display them, but
I'd like to place a sum of their @Value after each item.

MS XML 4 SP2 and using XSL (using the Meunchian method).

XML looks like:

<Bonus>
<BonusItem Name="Category One" Value="1"/>
<BonusItem Name="Category One" Value="1"/>
<BonusItem Name="Category Two" Value="2"/>
<BonusItem Name="Category One" Value="1"/>
<BonusItem Name="Category Two" Value="2"/>
<BonusItem Name="Category Six" Value="6"/>
</Bonus>

and the output should look like:

Category One: 3
Category Two: 4
Category Six: 6

I've tried sum(@Value) inside a for-each but it doesn't give
me the total.

Thanks for your help.
Jul 20 '05 #1
3 1317
Hello, Gadrin77!
You wrote on 12 May 2004 15:52:21 -0700:
[Sorry, skipped]

You can use the following code snippet:
[xslt]
<xsl:template match="Bonus">
<xsl:apply-templates select="BonusItem[not(@Name =
preceding-sibling::BonusItem/@Name)]"/>
</xsl:template>

<xsl:template match="BonusItem">
<xsl:element name="{@Name}">
<xsl:value-of select="sum(//Bonus/BonusItem[@Name =
current()/@Name]/@Value)" />
</xsl:element>
</xsl:template>
[/xslt]

Could you provide your code what uses Meunchian method? I don't uderstand
the problem with the sum function.

With best regards, Alex Shirshov.
Jul 20 '05 #2
"Alex Shirshov" <no****@mail.ru> wrote in message news:<c7**********@news.gamma.ru>...
Hello, Gadrin77!
You wrote on 12 May 2004 15:52:21 -0700:
[Sorry, skipped]

You can use the following code snippet:
[xslt]
<xsl:template match="Bonus">
<xsl:apply-templates select="BonusItem[not(@Name =
preceding-sibling::BonusItem/@Name)]"/>
</xsl:template>

<xsl:template match="BonusItem">
<xsl:element name="{@Name}">
<xsl:value-of select="sum(//Bonus/BonusItem[@Name =
current()/@Name]/@Value)" />
</xsl:element>
</xsl:template>
[/xslt]

Could you provide your code what uses Meunchian method? I don't uderstand
the problem with the sum function.

With best regards, Alex Shirshov.


thanks Alex,

here's the current incarnation (which I've edited and re-edited
several
times).

I'm still new to XSL and forgot all about Current()

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

<xsl:key name="BonusCategory" match="BonusItem" use="@Name"/>

<xsl:template match="/*">
<xsl:for-each select="/Bonus/BonusItem[count(. |
key('BonusCategory', @Name)[1])=1]">
<!-- <xsl:sort select="@Name" order="ascending"/> -->
<xsl:value-of select="@Name"/>
<xsl:text>:</xsl:text><xsl:text> </xsl:text>
<xsl:value-of select="@Value"/>

<br/>
</xsl:for-each>

</xsl:template>

</xsl:stylesheet>
Jul 20 '05 #3
Hello, Gadrin77!
You wrote on 13 May 2004 09:27:22 -0700:
[Sorry, skipped]

G> thanks Alex,

G> here's the current incarnation (which I've edited and re-edited
G> several
G> times).

G> I'm still new to XSL and forgot all about Current()

G> <?xml version='1.0'?>
G> <xsl:stylesheet version="1.0"
G> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

G> <xsl:key name="BonusCategory" match="BonusItem" use="@Name"/>

G> <xsl:template match="/*">
G> <xsl:for-each select="/Bonus/BonusItem[count(. |
G> key('BonusCategory', @Name)[1])=1]">
G> <!-- <xsl:sort select="@Name" order="ascending"/> -->
G> <xsl:value-of select="@Name"/>
G> <xsl:text>:</xsl:text><xsl:text> </xsl:text>
G> <xsl:value-of select="@Value"/>

G> <br/>
G> </xsl:for-each>

G> </xsl:template>

Here you just get value of the first BonusItem in the group. If you want to
get sum of all values in corresponding group of items, the code will looks
like:

<xsl:value-of select="@Name"/>
<xsl:text>: </xsl:text>
<xsl:value-of select="sum(key('BonusCategory', @Name)/@Value)" />
<br/>

With best regards, Alex Shirshov.
Jul 20 '05 #4

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

Similar topics

4
by: jane | last post by:
HI, I try to create summary table like following: create table summary (a int, b int, c int) (select a.aa, b.bb, b.cc from table_a a ,table_b b where a.key=b.key) data initially deferred...
2
by: srusskinyon | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for...
1
by: AccessHunter | last post by:
Hi, I have a report for Judges and their cases Numbers, grouped by Judge Name,the detail starts on a new page every time a judge changes. On the Judge footer I am displaying Count of Total no of...
1
by: annemariearmour | last post by:
I am using Crystal reports version 11.2 to create reports. The data source is SQL Server, and I am using views rather than reporting directly from tables. I apply selection criteria to the incoming...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.