Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Tweak xsl to eliminate duplicate data and blank lines

Reply
Thread Tools

Tweak xsl to eliminate duplicate data and blank lines

 
 
Luke Airig
Guest
Posts: n/a
 
      12-23-2003
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"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xslutput 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
 
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
How to eliminate duplicate pictures? Jan Nademlejnsky Digital Photography 3 12-02-2009 03:36 PM
Preserve blank lines when add multiple lines of text to a cell Cah Sableng Javascript 0 04-23-2007 04:46 AM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
XSL & XML newbie: How to get rid of blank lines in output?? ricky XML 1 10-17-2004 08:28 PM
OE add on to eliminate duplicate messages Me Computer Support 3 06-25-2003 01:04 PM



Advertisments