473,404 Members | 2,137 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,404 software developers and data experts.

XML Grouping Problem

I am having trouble grouping using xslt 1.0

Below is a sample stylesheet and xml file. My end result would be a list of distinct "@Keyword" for a given Store and the sum of their "@Count"


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="distinct-keywords" match="Klog" use="@Keyword"></xsl:key>
<xsl:template match="/">
<div>
<table width="100%" cellpadding="4" cellspacing="4" border="0">
<tr>
<td colspan="3"><h3><xsl:value-of select="doc/ReportName"/></h3></td></tr>
<tr><td colspan="3"><h5><xsl:value-of select="doc/StartDate"/> -
<xsl:value-of select="doc/EndDate"/></h5></td>

</tr>
<xsl:for-each select="doc/StatsReport/Store">
<tr valign="top" align="left">
<td>
<br></br>
<h5>
Store: <xsl:value-of select="@Number"/>
</h5>
</td>
<td/>
<td/>
</tr>

<xsl:for-each select=".//Klog[generate-id(.) = generate-id(key('distinct-keywords', .//@Keyword)[1])]">
<tr valign="top" align="left" >
<td>
<xsl:value-of select="@Keyword"/>
</td>
<td>
<xsl:value-of select="sum(@Count)"/>
</td>
</tr>
</xsl:for-each>

</xsl:for-each>


</table>
</div>
</xsl:template>
</xsl:stylesheet>

XML Below:



<?xml version="1.0"?>
<doc>
<ReportName>SampleReport</ReportName>
<StartDate>Sep 12 2007 12:00AM</StartDate>
<EndDate>Sep 17 2007 11:59PM</EndDate>
<StatsReport>
<Store Number="ST101">
<ID ID="ST1010">
<Klog Keyword=" Key 1" SubKeyword="" Count="1"/>
<Klog Keyword=" Key 1" SubKeyword="" Count="1"/>
<Klog Keyword=" Key 2" SubKeyword="" Count="2"/>
<Klog Keyword=" Key 1" SubKeyword="" Count="1"/>
<Klog Keyword=" Key 2" SubKeyword="" Count="1"/>
<Klog Keyword=" Key 1" SubKeyword="" Count="3"/>
</ID>
<ID ID="ST1011">
<Klog Keyword=" Key 4" SubKeyword="" Count="1"/>
<Klog Keyword=" Key 1" SubKeyword="" Count="1"/>
<Klog Keyword=" Key 2" SubKeyword="" Count="2"/>
<Klog Keyword=" Key 1" SubKeyword="" Count="1"/>
<Klog Keyword=" Key 2" SubKeyword="" Count="1"/>
<Klog Keyword=" Key 1" SubKeyword="" Count="3"/>
</ID>
<ID ID="ST1012">
<Klog Keyword=" Key 1" SubKeyword="" Count="1"/>
<Klog Keyword=" Key 3" SubKeyword="" Count="1"/>
<Klog Keyword=" Key 2" SubKeyword="" Count="2"/>
<Klog Keyword=" Key 1" SubKeyword="" Count="1"/>
<Klog Keyword=" Key 2" SubKeyword="" Count="1"/>
<Klog Keyword=" Key 1" SubKeyword="" Count="3"/>
</ID>
</Store>
</StatsReport>
</doc>

Here is the output I am looking for:


Store Number : ST101

Key 1 16
Key 2 9
Key 3 1
Key 4 1

Here is what I am getting :

Key 1 6
Key 2 3
Key 3 1
Key 4 1

I always get the correct list of Keywords but the sum is only for one ID. Anyone have any ideas? Any help is appreciated
Sep 18 '07 #1
2 1510
jkmyoung
2,057 Expert 2GB
<xsl:value-of select="sum(key('distinct-keywords', @Keyword)/@Count)">
Sep 18 '07 #2
Thanks. Works perfect
Sep 19 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Debbie Davis | last post by:
Hi there, SQL 2000 I have the following query: SELECT sponsor, COUNT(sponsor) * 2 AS total FROM Referrals GROUP BY sponsor Works great, returns the sponsor and the total * 2 of their...
5
by: Jody Greening | last post by:
Transforming with XSLT, Grouping elements until difference found. I am seeking some help with the following problem, I am fairly new at XSLT transformations, and my problem may lie in looking at...
2
by: Andreas Håkansson | last post by:
Seeing how my previous post seem to have fallen between the cracks, I thought I would have a second, more direct, go at it. So my question is "Is it possible to group (Muenchian method) over...
1
by: Brian Coy | last post by:
I am creating a database to track scrap on a daily basis at my plant. I have to provide a weekly scrap report with the amount of each part scrapped per day. I have the basic database set up, and...
3
by: ahaque38 | last post by:
Hello. Using A2K SP3, I am having the following problem with a report using "Sorting and Grouping". I have recently added a grouping in the reports for "Category2<>'CONTRACTS'". I have...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
0
by: virendra | last post by:
hi, I am working on crystal report 9 in asp.net. I created multilevel dynamic grouping in CR. if page is load firsttime. and i am giving firstlevel of grouping or whatever it's working fine. but...
0
by: Corey | last post by:
hello, I’m trying to run a query and I’m getting error messages Can anyone help me get though this problem? 1: Tried this and got this error message ORA-00923 , decode...
4
by: Chris | last post by:
I tried to retrieve the digit grouping symbol in MSAccess but unfortunately 3;0 is retrieved instead of comma which is my symbol. Function retrieves decimal symbol and list separator without any...
6
patjones
by: patjones | last post by:
Good afternoon: This seems like it shouldn't be hard, and then again this is how so many problems seem at the outset. My situation is this: I have a report called rptMain319, which is based...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.