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