Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

54 views
Skip to first unread message

Frank

unread,
Sep 11, 2003, 8:53:39 PM9/11/03
to
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>John</frstname>
<email>1@1.1</email>
</client>
<client>
<number>0067</number>
<lastname>Carter</lastname>
<frstname>Gary</frstname>
<email>2@2.2</email>
</client>
</clients>
<clients cat="prvt">
<client>
<number>0076</number>
<lastname>Lavigne</lastname>
<frstname>Avril</frstname>
<email>3@3.3</email>
</client>
<client>
<number>0055</number>
<lastname>Donnely</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>John</frstname>
<email>1@1.1</email>
</client>
</clients>
<clients cat="prvt">
<client>
<number>0076</number>
<lastname>Lavigne</lastname>
<frstname>Avril</frstname>
<email>3@3.3</email>
</client>
<client>
<number>0055</number>
<lastname>Donnely</lastname>
<frstname>Al</frstname>
<email>4@4.4</email>
</client>
<client>
<number>0067</number>
<lastname>Carter</lastname>
<frstname>Gary</frstname>
<email>2@2.2</email>
</client>
</clients>
</root>

THANKS!

Dimitre Novatchev

unread,
Sep 12, 2003, 1:22:39 AM9/12/03
to
A simple way to do this:

<xsl:stylesheet 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>

</file1>
<file2>

</file2>
</files>


the wanted result is produced:

<client>
<number>0067</number>
<lastname>Carter</lastname>
<frstname>Gary</frstname>
<email>2@2.2</email>
</client>
<client>
<number>0067</number>
<lastname>Carter</lastname>
<frstname>Gary</frstname>
<email>2@2.2</email>
</client>


=====
Cheers,

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

"Frank" <francoi...@yahoo.com> wrote in message
news:236d7175.03091...@posting.google.com...

0 new messages