xsl-list
[Top] [All Lists]

RE: Conditional merge of 2 XML files

2005-08-31 06:16:04
Unfortunately, for a newcomer to the language, you've selected a rather
difficult problem. I'm not sure I even understand the problem fully, for
example I don't understand whether the order of elements in the two files is
important: I get the impression that it is. This leads to all sorts of
questions, for example if the sequence in the first file is

A B F G

and in the second is

A D G F

what output do you want?

Also, presumably the hierarchy is important, so

<second>A B C</second><second>D E F</second>

is not the same as

<second>A B C D</second><second>E F</second>

I think the solution to this is going to involve a recursive walk of the two
trees in parallel: that is, a recursive template which is passed two
parameters, being the current position in both trees; it then needs to do
some analysis of what it finds at those positions, and then call itself
recursively, having advanced one or both of the two positions.

That's just a sketch, I don't have time to work it out more fully. It isn't
an exercise I would set on a beginner's course.

Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: Thomas Tarpin-Lyonnet [mailto:bartleby(_at_)t-bart(_dot_)net] 
Sent: 31 August 2005 03:41
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Conditional merge of 2 XML files

Hello,
I'm a newbie in XSL and I would like to do something with 2 
XML files and i
can't manage to do it.
Here is my problem.
I have 2 XML files, file_1.xml and file_2.xml structured as follow:
file_1.xml:
<?xml version="1.0"?>
<firstTag>
  <secondTag>
    <thirdTag> Thomas </thirdTag>
    <thirdTag> Tarpin </thirdTag>
  </secondTag>
  <secondTag>
    <thirdTag> Pipo </thirdTag>
    <thirdTag> Pipolaki </thirdTag>
  </secondTag>
</firstTag>

file_2.xml:
<?xml version="1.0"?>
<firstTag>
  <secondTag>
    <thirdTag here="Yes"> Thomas </thirdTag>
    <thirdTag here="Yes"> - </thirdTag>
    <thirdTag here="Yes"> Lyonnet </thirdTag>
  </secondTag>
  <secondTag>
    <thirdTag here="Yes"> Pipo </thirdTag>
    <thirdTag here="Yes"> Pipolaki </thirdTag>
  </secondTag>
</firstTag>

I would like to be able to do the diff between the two files 
and generate
another xml that will be the result of the merging of the two 
files only if
there are some thirdTag that are defined in file_1.xml and missing in
file_2.xml. Otherwise if the two files contains the same 
thirdTag then the
result.xml will be the same as file_2.xml.
The resulting file would be something like that:
result.xml:
<?xml version="1.0"?>
<firstTag>
  <secondTag>
    <thirdTag here="Yes"> Thomas </thirdTag>
    <thirdTag here="No"> Tarpin </thirdTag>
    <thirdTag here="Yes"> - </thirdTag>
    <thirdTag here="Yes"> Lyonnet </thirdTag>
  </secondTag>
  <secondTag>
    <thirdTag here="Yes"> Pipo </thirdTag>
    <thirdTag here="Yes"> Pipolaki </thirdTag>
  </secondTag>
</firstTag>

I know that i have to use the document() function but i don't 
know how.
How can i do that ? I'm a bit confused, i tried but i can't.
Anybody to help me ?

Thanks

Thomas

*********************************
*     Thomas Tarpin-Lyonnet     *
* http://jaccal.sourceforge.net *
*********************************




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>