By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 1,211 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

Tweak xsl to eliminate duplicate data and blank lines

P: n/a
I am trying to merge two xml files based on common date/time and then
write out a tab-delimited xml file with the header record from one of
the input files concatenated in front of the merged detail records in
the output file. The version I have is close to what I need except it
concatenates two sets of header records in front of each merged detail
record and the first two lines in the file and the last line is blank.

Can someone please tell me how to tweak the xsl stylesheet to get rid
of the duplicate concatenated header fields and the blank lines?

Here are the xsl and xml files:

merge_lrv_gps_and_trans_to_tab_delim.xsl:
-----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:variable name="delim" select="'&#x9;'"/> <!-- tab -->
<xsl:variable name="nl" select="'&#xA;'"/> <!-- newline -->
<xsl:variable name="head">
<xsl:for-each select="/root/header/*">
<xsl:value-of select="concat(., $delim)"/>
</xsl:for-each>
</xsl:variable>

<xsl:template match="/root/record">
<!--note: if lrv_gps.xml is in a different directory, you will
need to use the relative path or URL-->
<xsl:variable name="gps"
select="document('lrv_gps.xml')/root/record[date_time =
current()/date_time]"/>
<xsl:value-of select="$head"/>
<xsl:value-of select="concat($gps/longitude, $delim,
$gps/latitude, $delim)"/>
<xsl:for-each select="*">
<xsl:value-of select="concat(., $delim)"/>
</xsl:for-each>
</xsl:template>

<!--this empty template is to stop the header values from printing at
top of page-->
<xsl:template match="header">
</xsl:template>

</xsl:stylesheet>
lrv_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>
<record>
<longitude>-105.111111</longitude>
<latitude>39.111111</latitude>
<date_time>2003/12/10.17:08</date_time>
</record>
<record>
<longitude>-105.222222</longitude>
<latitude>39.222222</latitude>
<date_time>2003/12/10.17:18</date_time>
</record>
<record>
<longitude>-105.111111</longitude>
<latitude>39.111111</latitude>
<date_time>2003/12/10.17:28</date_time>
</record>
</root>

lrv_trans.xml:
--------------
<?xml version="1.0"?>
<root>
<header>
<driver_id>driver_id_from_trans</driver_id>
<vehicle_id>vehicle_id_from_trans</vehicle_id>
<duty_shift_id>duty_shift_id_from_trans</duty_shift_id>
<route_id>route_id_from_trans</route_id>
<cid_terminal_id>cid_terminal_id_from_trans</cid_terminal_id>
</header>
<record>
<date_time>2003/12/10.16:08</date_time>
<tag_id>tag_id_from_trans_1</tag_id>
<stop_location_id>stop_location_id_from_trans_1</stop_location_id>
<fare_type_cd>fare_type_cd_from_trans_1</fare_type_cd>
<blacklist_cd>blacklist_cd_from_trans_1</blacklist_cd>
</record>
<record>
<date_time>2003/12/10.16:18</date_time>
<tag_id>tag_id_from_trans_4</tag_id>
<stop_location_id>stop_location_id_from_trans_4</stop_location_id>
<fare_type_cd>fare_type_cd_from_trans_4</fare_type_cd>
<blacklist_cd>blacklist_cd_from_trans_4</blacklist_cd>
</record>
<header>
<driver_id>driver_id_from_trans</driver_id>
<vehicle_id>vehicle_id_from_trans</vehicle_id>
<duty_shift_id>duty_shift_id_from_trans</duty_shift_id>
<route_id>route_id_from_trans</route_id>
<cid_terminal_id>cid_terminal_id_from_trans</cid_terminal_id>
</header>
<record>
<date_time>2003/12/10.17:08</date_time>
<tag_id>tag_id_from_trans_1</tag_id>
<stop_location_id>stop_location_id_from_trans_1</stop_location_id>
<fare_type_cd>fare_type_cd_from_trans_1</fare_type_cd>
<blacklist_cd>blacklist_cd_from_trans_1</blacklist_cd>
</record>
<record>
<date_time>2003/12/10.17:18</date_time>
<tag_id>tag_id_from_trans_4</tag_id>
<stop_location_id>stop_location_id_from_trans_4</stop_location_id>
<fare_type_cd>fare_type_cd_from_trans_4</fare_type_cd>
<blacklist_cd>blacklist_cd_from_trans_4</blacklist_cd>
</record>
</root>
TIA
Jul 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.