[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Conditional merge of 2 XML files

Subject: RE: Conditional merge of 2 XML files
From: Thomas Tarpin-Lyonnet <bartleby@xxxxxxxxxx>
Date: Thu, 01 Sep 2005 10:54:32 +0800
xcrd
Hello,

I knew that it was something linked to recursive templates, i saw some
examples
in: http://www.dpawson.co.uk/xsl/sect2/merge.html#d6458e19 but i'm
unfortunately unable to understand them then unable to adapt them to my
problem
...
Yes, sorry, i omitted to say these important details. Yes, you were right, the
order is important then in your first example, the output expected would be: A
B D F G. Knowing that in each files the node values are ordered already.
Meaning that having in a file something like : A D G F will not be possible.
Regarding the hierarchie, for the two examples you gave me, the two examples
will give the same result: A B C D E F.
I think that it's better if i give you my concrete files:
My first file would be like that file_1.xml:
<?xml version="1.0"?>
<testCampaignResults>
 <xcrdApi>
   <xcrdApiTitle>XCRD Entry Points</xcrdApiTitle>
   <api>
     <apiName result="OK">GetVer</apiName>
     <testFamily>
       <familyName result="OK">GetVer_Nom</familyName>
       <testNum>
         <num result="OK">GetVer_Nom_T1</num>
         <case result="OK">GetVer_Nom_T1_C1</case>
         <case result="OK">GetVer_Nom_T1_C3</case>
       </testNum>
     </testFamily>
     <testFamily>
       <familyName result="OK">GetVer_Str</familyName>
       <testNum>
         <num result="OK">GetVer_Str_T1</num>
         <case result="OK">GetVer_Str_T1_C1</case>
       </testNum>
     </testFamily>
   </api>
 </xcrdApi>
</testCampaignResults>

and my second file would be like that, file_2.xml:
<?xml version="1.0"?>
<testCampaignResults>
<xcrdApi>
   <xcrdApiTitle>XCRD Entry Points</xcrdApiTitle>
   <api>
     <apiName>GetVer</apiName>
     <testFamily>
       <familyName>GetVer_Nom</familyName>
       <testNum>
         <num>GetVer_Nom_T1</num>
         <case>GetVer_Nom_T1_C1</case>
         <case>GetVer_Nom_T1_C2</case>
         <case>GetVer_Nom_T1_C3</case>
       </testNum>
     </testFamily>
     <testFamily>
       <familyName>GetVer_Str</familyName>
       <testNum>
         <num>GetVer_Str_T1</num>
         <case>GetVer_Str_T1_C1</case>
         <case>GetVer_Str_T1_C2</case>
       </testNum>
     </testFamily>
   </api>
   <api>
     <apiName>GetID</apiName>
     <testFamily>
       <familyName>GetID_Nom</familyName>
       <testNum>
         <num>GetID_Nom_T1</num>
         <case>GetID_Nom_T1_C1</case>
         <case>GetID_Nom_T1_C2</case>
         <case>GetID_Nom_T1_C3</case>
       </testNum>
     </testFamily>
   </api>
 </xcrdApi>
</testCampaignResults>

Then the resulting file should be: result.xml:
<?xml version="1.0"?>
<testCampaignResults>
 <xcrdApi>
   <xcrdApiTitle>XCRD Entry Points</xcrdApiTitle>
   <api>
     <apiName result="OK">GetVer</apiName>
     <testFamily>
       <familyName result="OK">GetVer_Nom</familyName>
       <testNum>
         <num result="OK">GetVer_Nom_T1</num>
         <case result="OK">GetVer_Nom_T1_C1</case>
         <case>GetVer_Nom_T1_C2</case>
         <case result="OK">GetVer_Nom_T1_C3</case>
       </testNum>
     </testFamily>
     <testFamily>
       <familyName result="OK">GetVer_Str</familyName>
       <testNum>
         <num result="OK">GetVer_Str_T1</num>
         <case result="OK">GetVer_Str_T1_C1</case>
         <case>GetVer_Str_T1_C2</case>
       </testNum>
     </testFamily>
   </api>
   <api>
     <apiName>GetID</apiName>
     <testFamily>
       <familyName>GetID_Nom</familyName>
       <testNum>
         <num>GetID_Nom_T1</num>
         <case>GetID_Nom_T1_C1</case>
         <case>GetID_Nom_T1_C2</case>
         <case>GetID_Nom_T1_C3</case>
       </testNum>
     </testFamily>
   </api>
 </xcrdApi>
</testCampaignResults>

Where file_1.xml are the logs generated by a test campaign and file_2.xml are
the reference logs generated thanks to a test plan. The aim of doing
this is to
show all the tests that have been defined by the test plan but that we
forgot to
implement and then that don't appear in the logs.
The alphabetical order is kept and the hierarchy is kept as well. If by
hierarchy you mean that for example "GetVer_Str_T1_C2" cannot be under
"GetVer_Nom" then yes i need to keep the hierarchy of my tree.

I hope i gave you all the elements needed. I will be greatful if somebody can
help me, i found a solution without recursive template (more like a C
code) but
it's not giving the expected result and dont keep the order.

Thanks again.

Thomas

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

Quoting Michael Kay <mike@xxxxxxxxxxxx>:

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@xxxxxxxxxx]
Sent: 31 August 2005 03:41
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  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 *
*********************************

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.