473,795 Members | 2,922 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

merge two xml files based on common key

I have two xml files that I need to merge on their common field
(date_time). The merged output file needs to have the date_time field
and all fields from both of the two input files. I am using the Saxon
xml parser. Can someone please help me to get this to work? The two
xml input files follow, as well as my attempt to write the merge xsl
(merge_on_date_ time.xsl):

lrv_1_transacti on_cid_1.xml:
----------------------------
<?xml version="1.0"?>
<root>
<record>
<date_time> 2003/12/10.16:08 </date_time>
<driver_id> TRANSIT_VEHICLE _ID1 </driver_id>
<vehicle_id> FARE_TYPE_CD1 </vehicle_id>
<duty_shift_i d> DUTY_SHIFT_ID_1 </duty_shift_id>
<route_id> ROUTE_ID_1 </route_id>
<cid_terminal_i d> CID_TERMINAL_ID </cid_terminal_id >
<tag_id> TAG_ID </tag_id>
</record>
</root>

lrv_1_gps_cid.x ml:
------------------
<?xml version="1.0"?>
<root>
<record>
<stop_location_ id> STOP_LOCATION_I D1 </stop_location_i d>
<latitude> 39.814658 </latitude>
<longitude> -105.183682 </longitude>
<date_time> 2003/12/10.16:08 </date_time>
<vehicle_id> TRANSIT_VEHICLE _ID1 </vehicle_id>
<fare_type_cd > FARE_TYPE_CD1 </fare_type_cd>
<blacklist_cd > V </blacklist_cd>
</record>
</root>

merge_on_date_t ime.xsl:
-----------------------
<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>

<!-- load the merge file -->
<xsl:variable name="transacti ons"
select="documen t('lrv_1_gps_ci d.xml')"/>
<xsl:template match="/">
<root>
<xsl:for-each select="root/record">
<!-- cache the key: date_time -->
<xsl:variable name="date_time ">
<xsl:value-of select="@date_t ime"/></xsl:variable>
<!-- copy the child nodes -->
<record>
<xsl:copy-of select="child:: *"/>
<!-- copy the children of the matching record node from the
merge file -->
<xsl:copy-of
select="$transa ctions/root/record[@date_time=$dat e_time]/child::*"/>
</record>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>

TIA
Jul 20 '05 #1
1 4117
In article <a0************ **************@ posting.google. com>,
Luke Airig <lu********@hot mail.com> wrote:

% (date_time). The merged output file needs to have the date_time field
% and all fields from both of the two input files. I am using the Saxon

Note that the `date_time' field is an element.

[...]

% lrv_1_transacti on_cid_1.xml:
[...]
% <date_time> 2003/12/10.16:08 </date_time>
[...]
% lrv_1_gps_cid.x ml:
[...]
% <date_time> 2003/12/10.16:08 </date_time>

Also note that the contents of these two date_time elements are not
the same.

[...]

% merge_on_date_t ime.xsl:

[...]

% <xsl:variable name="date_time ">
% <xsl:value-of select="@date_t ime"/></xsl:variable>

What you're doing here is getting the value of the date_time
attribute, which doesn't exist.

[...]

% <xsl:copy-of
% select="$transa ctions/root/record[@date_time=$dat e_time]/child::*"/>

Which you then compare to a date_time attibute, which doesn't exist.
The first part of the solution is to lose the @s. The second part
is to account for the difference in the number of spaces. You can
use the xpath function normalize-space() to do that, changing those
to excerpts to

<xsl:variable name="date_time " select="normali ze-space(date_time )"/>

and

<xsl:copy-of
select="$transa ctions/root/record[normalize-space(date_time )
=$date_time]/child::*"/>

This leads to a couple of other possible problems. The date_time
element is duplicated. You can filter it out by adding
[name() != 'date_time']
to the end of the select expression.

The other is that the xml is not formatted too well. You might be
able to deal with that (assuming you care) by adding the attribute
indent='yes' to the xsl:method element.
--

Patrick TJ McPhee
East York Canada
pt**@interlog.c om
Jul 20 '05 #2

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

Similar topics

2
10205
by: MAF | last post by:
Is there a quick way to merge two XML files example A <TestNode> <Data>123</Data> </TestNode> <TestNode> <Data>123</Data> <Data>222</Data>
4
5457
by: lesperancer | last post by:
I have 3 tables (office97) tblQuote quoteNbr tblDetails ( quote : 1 <-> M: quoteDetails) quoteNbr detailLine product value
4
21685
by: John J. Hughes II | last post by:
Could someone explain how to merge the form menu with the mdi container window. The menu strip items on the form window merge but I either end up with a blank blue menu on the form or top list of items that don't do anything. MDI Container.IsMdiContainer = true MenuStrip.AllowMerge = true /// First menu items this.miFile.MergeAction = System.Windows.Forms.MergeAction.Insert;
4
4957
by: Andreas Kasparek | last post by:
Hola! I'm preparing my master thesis about a XML Merge Tool implementation and was wondering if there is any open standard for XML diff regarding topics like: - is a diff result computed on the ordered or unordered xml node tree of the compared documents? - what identifiers/criteria should be used by default to match elements of the same type in different documents? - should a diff tool consider move operations or only insert/delete
2
3418
by: gtslabs | last post by:
I have searched the archives for answers with no luck. I am now using Access 2003 from Lotus Approach. I see that Access does not have any built in envelope or mailing lable features. I want to have a standard letter that I use with a mailing label. I tried WORD for the mail merge but I have my contact data in one data file (table) and my projects in a different data file (table) . So my standard letter which is a transmittal needs to...
4
7224
by: Tom Jones | last post by:
I have an application that was originally built using Visual Studio 2003 that I upgraded to Visual Studio 2005. When I attempt to build the *.msi file in the deployment project, I am getting a compile error stating that it cannot find: "C:\Program Files\Common Files\Merge Modules\Crystal_regwiz2003.msm" I am not sure where to get this file or even if it is appropriate (i.e., should there be a newer version for Visual Studio 2005).
9
8288
by: Peter | last post by:
Does anyone has .NET library to merger RTF files? Thank You Peter
0
1607
by: Claire | last post by:
Hi, I developed an application that uses Crystal Reports in visual studio 2005 then ported the whole application to VS2008. My original setup/deployment application (created within visual studio) for this project included files CrystalReportsRedist2005_x86.msm, microsoft_vc80_atl_x86.msm and policy_8_0_Microsoft_vc80_atl_x86.msm all situated in c:\program files\common files\merge modules directory. My ported application still uses dotnet...
1
14889
by: cristalink | last post by:
Hi, I have MS Visual Studio 2008 both Pro and Dev Team Edition SP1 installed. I've compiled a managed C++ .DLL which automatically had a manifest embedded, with the following dependency: "Microsoft.VC90.CRT" "9.0.21022.8" "x86". I created an MSI package with the following merge modules: "Program Files\Common Files\Merge Modules\Microsoft_VC90_CRT_x86.msm" and "policy_9_0_Microsoft_VC90_CRT_x86.msm".
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10439
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10215
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9043
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5437
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.