473,567 Members | 2,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using XSL to compare two XML files - Need help please!

Hi, is there a way to use XSL to compare two XML files to verify if a
"record"
in an XML file has changed of parent in another XML file ?

I am trying to implement a template in an XSL stylesheet that would be able
to compare the two files below
and indicate if a client has changed of category (ex.: from "corp" to
"prvt").

Any help would be gladly appreciated, I am desparatly trying to find a
solution to this.

In the above example, client number 0067 has changed
from "corp" (in file1.xml) to "prvt" (in file2.xml).

file1.xml:
-----------

<root>
<clients cat="corp">
<client>
<number>0098</number>
<lastname>Smith </lastname>
<frstname>Joh n</frstname>
<email>1@1.1</email>
</client>
<client>
<number>0067</number>
<lastname>Carte r</lastname>
<frstname>Gar y</frstname>
<email>2@2.2</email>
</client>
</clients>
<clients cat="prvt">
<client>
<number>0076</number>
<lastname>Lavig ne</lastname>
<frstname>Avril </frstname>
<email>3@3.3</email>
</client>
<client>
<number>0055</number>
<lastname>Donne ly</lastname>
<frstname>Al</frstname>
<email>4@4.4</email>
</client>
</clients>
</root>

file2.xml:
-----------

<root>
<clients cat="corp">
<client>
<number>0098</number>
<lastname>Smith </lastname>
<frstname>Joh n</frstname>
<email>1@1.1</email>
</client>
</clients>
<clients cat="prvt">
<client>
<number>0076</number>
<lastname>Lavig ne</lastname>
<frstname>Avril </frstname>
<email>3@3.3</email>
</client>
<client>
<number>0055</number>
<lastname>Donne ly</lastname>
<frstname>Al</frstname>
<email>4@4.4</email>
</client>
<client>
<number>0067</number>
<lastname>Carte r</lastname>
<frstname>Gar y</frstname>
<email>2@2.2</email>
</client>
</clients>
</root>

THANKS!
Jul 20 '05 #1
1 5934
A simple way to do this:

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="/*/file1/*/*/client">
<xsl:if test="not(../@cat = /*/file2/*/*/client[number =
current()/number]/../@cat)">
<xsl:copy-of select=". | /*/file2/*/*/client[number =
current()/number]" />
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

when this transformation is applied on this source.xml (I combined the two
files in one for convenience -- you'll have to use document()):

<files>
<file1>
<root>
<clients cat="corp">
<client>
<number>0098</number>
<lastname>Smith </lastname>
<frstname>Joh n</frstname>
<email>1@1.1</email>
</client>
<client>
<number>0067</number>
<lastname>Carte r</lastname>
<frstname>Gar y</frstname>
<email>2@2.2</email>
</client>
</clients>
<clients cat="prvt">
<client>
<number>0076</number>
<lastname>Lavig ne</lastname>
<frstname>Avril </frstname>
<email>3@3.3</email>
</client>
<client>
<number>0055</number>
<lastname>Donne ly</lastname>
<frstname>Al</frstname>
<email>4@4.4</email>
</client>
</clients>
</root>
</file1>
<file2>
<root>
<clients cat="corp">
<client>
<number>0098</number>
<lastname>Smith </lastname>
<frstname>Joh n</frstname>
<email>1@1.1</email>
</client>
</clients>
<clients cat="prvt">
<client>
<number>0076</number>
<lastname>Lavig ne</lastname>
<frstname>Avril </frstname>
<email>3@3.3</email>
</client>
<client>
<number>0055</number>
<lastname>Donne ly</lastname>
<frstname>Al</frstname>
<email>4@4.4</email>
</client>
<client>
<number>0067</number>
<lastname>Carte r</lastname>
<frstname>Gar y</frstname>
<email>2@2.2</email>
</client>
</clients>
</root>
</file2>
</files>
the wanted result is produced:

<client>
<number>0067</number>
<lastname>Carte r</lastname>
<frstname>Gar y</frstname>
<email>2@2.2</email>
</client>
<client>
<number>0067</number>
<lastname>Carte r</lastname>
<frstname>Gar y</frstname>
<email>2@2.2</email>
</client>
=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Frank" <fr************ *@yahoo.com> wrote in message
news:23******** *************** ***@posting.goo gle.com...
Hi, is there a way to use XSL to compare two XML files to verify if a
"record"
in an XML file has changed of parent in another XML file ?

I am trying to implement a template in an XSL stylesheet that would be able to compare the two files below
and indicate if a client has changed of category (ex.: from "corp" to
"prvt").

Any help would be gladly appreciated, I am desparatly trying to find a
solution to this.

In the above example, client number 0067 has changed
from "corp" (in file1.xml) to "prvt" (in file2.xml).

file1.xml:
-----------

<root>
<clients cat="corp">
<client>
<number>0098</number>
<lastname>Smith </lastname>
<frstname>Joh n</frstname>
<email>1@1.1</email>
</client>
<client>
<number>0067</number>
<lastname>Carte r</lastname>
<frstname>Gar y</frstname>
<email>2@2.2</email>
</client>
</clients>
<clients cat="prvt">
<client>
<number>0076</number>
<lastname>Lavig ne</lastname>
<frstname>Avril </frstname>
<email>3@3.3</email>
</client>
<client>
<number>0055</number>
<lastname>Donne ly</lastname>
<frstname>Al</frstname>
<email>4@4.4</email>
</client>
</clients>
</root>

file2.xml:
-----------

<root>
<clients cat="corp">
<client>
<number>0098</number>
<lastname>Smith </lastname>
<frstname>Joh n</frstname>
<email>1@1.1</email>
</client>
</clients>
<clients cat="prvt">
<client>
<number>0076</number>
<lastname>Lavig ne</lastname>
<frstname>Avril </frstname>
<email>3@3.3</email>
</client>
<client>
<number>0055</number>
<lastname>Donne ly</lastname>
<frstname>Al</frstname>
<email>4@4.4</email>
</client>
<client>
<number>0067</number>
<lastname>Carte r</lastname>
<frstname>Gar y</frstname>
<email>2@2.2</email>
</client>
</clients>
</root>

THANKS!

Jul 20 '05 #2

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

Similar topics

0
4577
by: vaggelis | last post by:
I am interested to hear from colleagues that used Quicktest professional two compare two xML files. I am interesting specifically to hear how much success they had to parametize the filenames and allow the tool to compare hundreds of files in two runs. If possible please respond also to my e-mail id. vaggelis@rogers.com Thank you...
1
2655
by: Nick Leeson | last post by:
I have two HTML files - call it file1.html and file2.html.Is there a utility in Linux that I can use to visually compare the difference between the two files.Please note that I need to display and examine the difference in a Web browser like Mozilla. Otherwise I could have used the simple 'diff' utility. I know a utility called DiffnMerge...
5
7369
by: Colin Anderson | last post by:
I discovered, with great excitement, this article http://www.davison.uk.net/vb2notes.asp when researching methods for emailing from Access via Notes. Unfortunatly, when I run this I get a Run-time error. When I run it on an XP machine it crashes, but on an NT box it just generates an unknown error, handled by the error handler. I have...
11
6566
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on where the job is running, the job runs sucessfully, PDF files got generated, everything is good. If I scheduled the job to run at the time that I am...
2
3886
by: kids_pro | last post by:
What is the best method for comparing 2 file? I want to create a utilities to syncronize 2 folders that perform function similiar to robocopy.exe Thanks, kids
4
2363
by: CodeRazor | last post by:
Hi, I want to retrieve a sorted list of files, ordered by LastWriteTime. I know I can implement IComparer, but I don't know how or what this means. I know a sortedlist has objects and keys and that I could make the key for my sorted list the LastWriteTime of the file. Apart from this i'm at a real loose end. Any clues anyone?
0
2383
by: richardkreidl | last post by:
I have the following hash script that I use to compare two text files. 'Class Public Class FileComparison Public Class FileComparisonException Public Enum ExceptionType U 'Unknown A 'Add D 'Delete
6
6829
by: yinglcs | last post by:
Hi, i have 2 files which are different (1 line difference): $ diff groupresult20070226190027.xml groupresult20070226190027-2.xml 5c5 < x:22 y:516 w:740 h:120 area: --- But when I use the cmp() function to compare 2 files, it return "1",
1
6306
by: Lars B | last post by:
Hey guys, I have written a C++ program that passes data from a file to an FPGA board and back again using software and DMA buffers. In my program I need to compare the size of a given file against a software buffer of size 3MB. This is needed so as to see which function to use to read from the file. As the files used range from very large...
0
8115
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...
1
7651
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...
0
7960
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...
0
6272
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5216
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...
0
3648
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...
0
3630
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1205
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
930
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.