Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Merge two xml files on common date field and write out tab-delimited file

Reply
Thread Tools

Merge two xml files on common date field and write out tab-delimited file

 
 
Luke Airig
Guest
Posts: n/a
 
      12-21-2003
I am using the Saxon xml parser and I need some help transforming the
following 2 xml files:

gps.xml:
--------
<?xml version="1.0"?>
<root>
<record>
<longitude>-105.111111</longitude>
<latitude>39.111111</latitude>
<date_time>2003/12/10.16:08</date_time>
</record>
<record>
<longitude>-105.222222</longitude>
<latitude>39.222222</latitude>
<date_time>2003/12/10.16:18</date_time>
</record>
<record>
<longitude>-105.111111</longitude>
<latitude>39.111111</latitude>
<date_time>2003/12/10.16:28</date_time>
</record>
</root>

trans.xml:
----------
<?xml version="1.0"?>
<root>
<header>
<driver_id>driver_id1</driver_id>
<vehicle_id>vehicle_id1</vehicle_id>
<duty_shift_id>duty_shift_id1</duty_shift_id>
<route_id>route_id1</route_id>
<cid_terminal_id>cid_terminal_id1</cid_terminal_id>
</header>
<record>
<date_time>2003/12/10.16:08</date_time>
<tag_id>tag_id1</tag_id>
<stop_location_id>stop_location_id1</stop_location_id>
<fare_type_cd>fare_type_cd1</fare_type_cd>
<blacklist_cd>blacklist_cd1</blacklist_cd>
</record>
<record>
<date_time>2003/12/10.16:18</date_time>
<tag_id>tag_id2</tag_id>
<stop_location_id>stop_location_id2</stop_location_id>
<fare_type_cd>fare_type_cd2</fare_type_cd>
<blacklist_cd>blacklist_cd2</blacklist_cd>
</record>
</root>

I have a klugey, multiple-step solution right now and I would like a
single xsl stylesheet to:

1. Merge the two input file <record>'s on the date_time field.
2. Pass the <header> through as well and wind up with a
tab-delimited flat file with the <header> fields appended to the front
of each group of <record> fields as follows:

merged_tab_delimited.xml:
-------------------------
driver_id1 vehicle_id1 duty_shift_id1 route_id1 cid_terminal_id1
-105.111111 39.111111 2003/12/10.16:08 tag_id1 stop_location_id1
fare_type_cd1 blacklist_cd1

driver_id1 vehicle_id1 duty_shift_id1 route_id1 cid_terminal_id1
-105.222222 39.222222 2003/12/10.16:18 tag_id2 stop_location_id2
fare_type_cd2 blacklist_cd2

I'm a total neophyte with xml and I'm sure there is a
straight-forward, elegant solution to this.

TIA
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Is there a way to merge two XML files via Python? Stefan Behnel Python 0 01-12-2012 04:39 PM
Is there a way to merge two XML files via Python? J Python 0 01-12-2012 04:04 PM
Merge two different xml files into one Kjetil Finsrud XML 0 11-23-2004 09:20 AM
[Ant] Merge two xml files Eirik Eldorsen XML 1 04-12-2004 05:02 PM
merge two xml files based on common key Luke Airig XML 1 12-16-2003 07:36 PM



Advertisments