473,385 Members | 1,944 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.

Xml to Xml: How to group depending on two atributes?

Hi all,
This is a urgent situation. I´m counting on you guys to
give some clue to get the right XSL Transformation.
I need do group all nested tags <Entry> inside tag
<Record> according to an unique combination of two
atributes ('Product' and 'Customer'). Something like: for
each concatenation of 'Product' and 'Customers' find all
<Entry> because this last tag as different 'Periods'

ORIGINAL XML (with lots of <Records>):

<HistoricSales>
<Record Product="1053865" Customer="10127876">
<Entry Period="6">
<Units Sold="0" Free="0" Return="0"/>
<Amounts Cost="0" Gross="0" Return="0"/>
</Entry>
</Record>
<Record Product="1053865" Customer="10127876">
<Entry Period="2">
<Units Sold="0" Free="0" Return="0"/>
<Amounts Cost="0" Gross="0" Return="0"/>
</Entry>
</Record>
<Record Product="1022222" Customer="0999999">
<Entry Period="3">
<Units Sold="0" Free="0" Return="0"/>
<Amounts Cost="0" Gross="0" Return="0"/>
</Entry>
</Record>
(...)
</HistoricSales>

FINAL XML:

<HistoricSales>
<Record Product="1053865" Customer="10127876">
<Entry Period="6">
<Units Sold="0" Free="0" Return="0"/>
<Amounts Cost="0" Gross="0" Return="0"/>
</Entry>
<Entry Period="2">
<Units Sold="0" Free="0" Return="0"/>
<Amounts Cost="0" Gross="0" Return="0"/>
</Entry>
</Record>
<Record Product="1022222" Customer="0999999">
<Entry Period="3">
<Units Sold="0" Free="0" Return="0"/>
<Amounts Cost="0" Gross="0" Return="0"/>
</Entry>
</Record>
(...)
</HistoricSales>

At this moment I trying Muenchian Method. Is this the
best way. Thanks in advance.
Nov 11 '05 #1
2 1548
Filipe wrote:
This is a urgent situation. I´m counting on you guys to
give some clue to get the right XSL Transformation.
I need do group all nested tags <Entry> inside tag
<Record> according to an unique combination of two
atributes ('Product' and 'Customer'). Something like: for
each concatenation of 'Product' and 'Customers' find all
<Entry> because this last tag as different 'Periods' At this moment I trying Muenchian Method. Is this the
best way. Thanks in advance.

Sure this is the best way in XSLT 1.0. It's as simple as

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="recordKey" match="Record" use="concat(@Product,'|',
@Customer)"/>
<xsl:template match="HistoricSales">
<HistoricSales>
<xsl:apply-templates
select="Record[count(.|key('recordKey',concat(@Product,'|',@Custo mer))[1])=1]"/>
</HistoricSales>
</xsl:template>
<xsl:template match="Record">
<Record>
<xsl:copy-of
select="@*|key('recordKey',concat(@Product,'|',@Cu stomer))"/>
</Record>
</xsl:template>
</xsl:stylesheet>
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
Thank you very much Oleg.
This is definitly the solution for me.
Thank you again for your effort even if it's was simple
solution.

PS: Peace to Israel
-----Original Message-----
Filipe wrote:
This is a urgent situation. I´m counting on you guys to give some clue to get the right XSL Transformation.
I need do group all nested tags <Entry> inside tag
<Record> according to an unique combination of two
atributes ('Product' and 'Customer'). Something like: for each concatenation of 'Product' and 'Customers' find all <Entry> because this last tag as different 'Periods'
At this moment I trying Muenchian Method. Is this the
best way. Thanks in advance.

Sure this is the best way in XSLT 1.0. It's as simple as

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="recordKey" match="Record"

use="concat(@Product,'|', @Customer)"/>
<xsl:template match="HistoricSales">
<HistoricSales>
<xsl:apply-templates
select="Record[count(.|key('recordKey',concat (@Product,'|',@Customer))[1])=1]"/> </HistoricSales>
</xsl:template>
<xsl:template match="Record">
<Record>
<xsl:copy-of
select="@*|key('recordKey',concat (@Product,'|',@Customer))"/> </Record>
</xsl:template>
</xsl:stylesheet>
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

.

Nov 11 '05 #3

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

Similar topics

0
by: From | last post by:
how to edit simple xml file in java ? i want to locate my parser on the last element(root) ad some element and its atributes and close that xml? please any idea i triead with sax but it didnt...
3
by: Sony Antony | last post by:
Hello: ( Please redirect me to the correct list if this is not where I m supposed to ask this question ) Our application essentially sends xml 'commands' to another system. These commands...
2
by: DKode | last post by:
Ok, Here is my XML File, it's pretty simple: <?xml version="1.0" encoding="utf-8" ?> <Dispositions> <Group Name="Unused"> <Disp>NA</Disp> <Disp>TCB</Disp> <Disp>WPC</Disp> </Group>
2
by: luke.crouch | last post by:
My server-side php script is generating an xml response with the following structure: <thread class='Columns'> <Id class='Column dataDetail'>12345</Id> <Command class='Column...
3
by: christopher.davidson | last post by:
Hello, I am working with XML files and utilizing Array functions to take the XML data and combined it with some html code to display a particular page. The process currently works like so: ...
2
by: reynard.michel | last post by:
Hi, I would like to translate an XML ISO-8859-1 document in UTF-8. For this I wrote the following XSL <?xml version="1.0"?> <xsl:stylesheet version="1.0"...
43
by: Christoph Schneegans | last post by:
Hi! Okay, so positions on "text/html" XHTML are totally contradicting. Anyway! I hope there's more consensus about "application/xml" XHTML. I've recently learned that Opera 9.0b2 does not only...
1
by: dotnetnoob | last post by:
i have a unusual problem or maybe to me :) i have a xml file that i need to insert xml element from a string string - /Box/BoxTest/Test i have a function that seperate the string out into...
2
by: D3liverance | last post by:
Hi, I have made a DTD, an XML file and an XSLT file. I have defined a picture element in the DTD with atributes src, width, height and type which are all defined as CDATA. I'm using the XSLT file...
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: 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
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
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,...

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.