473,799 Members | 3,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help - use XSLT to group by multiple values?

I'm using XSLT and .NET Framework 1.1 to try to transform XML to group
by multiple values, and I'm not succeeding. I have source XML that
looks like the following:

<Data>
<Flavor>
<Name>Vanilla </Name>
<StartDate>2007 0704</StartDate>
<EndDate>200712 31</EndDate>
</Flavor>
<Flavor>
<Name>Chocolate </Name>
<StartDate>2007 0704</StartDate>
<EndDate>200711 31</EndDate>
</Flavor>
<Flavor>
<Name>Strawberr y</Name>
<StartDate>2007 0804</StartDate>
<EndDate>200711 31</EndDate>
</Flavor>
<Flavor>
<Name>Mint</Name>
<StartDate>2007 0704</StartDate>
<EndDate>200711 31</EndDate>
</Flavor>
</Data>
I need to group the items together that have the same values for
StartDate and EndDate such that the output looks like the following:

<Groups>
<Group>
<Name>Group1</Name>
<Flavors>
<Name>Vanilla </Name>
</Flavors>
<StartDate>2007 0704</StartDate>
<EndDate>200712 31</EndDate>
</Group>
<Group>
<Name>Group2</Name>
<Flavors>
<Name>Chocolate </Name>
<Name>Mint</Name>
</Flavors>
<StartDate>2007 0704</StartDate>
<EndDate>200711 31</EndDate>
</Group>
<Group>
<Name>Group3</Name>
<Flavors>
<Name>Strawberr y</Name>
</Flavors>
<StartDate>2007 0804</StartDate>
<EndDate>200712 31</EndDate>
</Group2>
</Groups>

I've tried to use the Muenchian Method with keys, but I haven't been
successful. Can anyone please provide some assistance?

Thanks in advance

Jul 23 '07 #1
1 13387
n.phelge wrote:
I've tried to use the Muenchian Method with keys, but I haven't been
successful. Can anyone please provide some assistance?
Not sure where you had problems as you have not shown your XSLT but here
is a working XSLT 1.0 stylesheet:

<xsl:styleshe et
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="xml" indent="yes"/>

<xsl:strip-space elements="*"/>

<xsl:key name="by-date" match="Flavor" use="concat(Sta rtDate, '_',
EndDate)"/>

<xsl:template match="Data">
<Groups>
<xsl:apply-templates select="Flavor[generate-id() =
generate-id(key('by-date', concat(StartDat e, '_', EndDate))[1])]"
mode="group"/>
</Groups>
</xsl:template>

<xsl:template match="Flavor" mode="group">
<Group>
<Name><xsl:valu e-of select="concat( 'Group', position())"/></Name>
<Flavors>
<xsl:apply-templates select="key('by-date', concat(StartDat e,
'_', EndDate))/Name"/>
</Flavors>
<xsl:apply-templates select="StartDa te | EndDate"/>
</Group>
</xsl:template>

<xsl:template match="Name | StartDate | EndDate">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jul 23 '07 #2

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

Similar topics

5
1539
by: Chris Kettenbach | last post by:
Good Morning, Sorry for xposting. Just need a liitle help. I have an xml file that's generated from a database. How do I select distinct values from a field in xslt and then loop through the records and produce output. Example <registrations> <registration> <company>Awesome Printers</company> <first>John</first>
4
1833
by: Chris Kettenbach | last post by:
Hi Peter, I get error when processing the stylesheet. It errors here. <xsl:for-each select="registration)=1]"> specifically: Expression does not return a DOM node. registration)=1]<--
5
1604
by: Patrick.O.Ige | last post by:
I have an xml and i'm trying to loop each node... When i do FOR EACH i seem not to get my desired result I want to loop through and get only the values that matches the question i specified with the corresponding answers? I don't want to retrieve all the Answer and VoteAnswers nodes <xsl:for-each select="NSurveyVoter/Voter/Question/Answer"> <xsl:value-of select="Answer/Answer/text()"/>
1
3726
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online. Plz....Plz..Plz...
2
1663
by: Scott Zabolotzky | last post by:
I've got an XML file that contains both a data section and a custom schema section. The data may represent only a subset of the parameters defined by the schema. I'm new to XSLT and I'm trying to figure out how to generate a tranform that will create an HTML form from the schema section and populate the controls with the values from the data section (if present). I _think_ I'd be able to come up with the transform to generate
1
1210
by: n.phelge | last post by:
I'm using XSLT and .NET Framework 1.1 to try to transform XML to group by multiple values, and I'm not succeeding. I have source XML that looks like the following: <Data> <Flavor> <Name>Vanilla</Name> <StartDate>20070704</StartDate> <EndDate>20071231</EndDate> </Flavor>
4
7127
by: sadc1986 | last post by:
How does one introduce multiple worksheets in a excel using Xslt Transforms my code... Please suggest <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"> <xsl:output method="html" encoding="UTF-8"/>
2
22780
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values in the attribute of an element. Instead of using the <xsl:attribute> element, you can simply place the xpath in the attribute itself. The most common usage of this is in creating hyperlinks.
1
5712
by: Sandeep Singh | last post by:
Hi, How to do group by in XSLT ? I tried on the following codes: <files> <file name="swablr.eps" size="4313" project="mars"/> <file name="batboy.wks" size="424" project="neptune"/> <file name="potrzebie.dbf" size="1102" project="jupiter"/>
2
2000
Dormilich
by: Dormilich | last post by:
Hi, I'm testing my classes for a web page and I stumble upon an error I don't have a clue what it means: Error: Fatal error: Can't use method return value in write context in "output.php" on line 142 (line 12 in snippet) the error is caused by this call: empty($inSeite_inp->getValue('PAR_NAME')) method definition see second snippet, lines 142 to 166
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10251
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10228
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7565
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.