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

Home Posts Topics Members FAQ

match muliple header records to associated detail records

I am using the Saxon engine and I have an xml file that contains
batches of records. Each batch starts with a header record and the
associated detail records immediately follow each header. There can
be multiple batches in
a single file, each batch indicated by a new header.

I need to create a tab-delimited output file that appends all of the
header record fields in front of each associated detail record within
the same batch. The following xsl works for a file with a single
batch/header but not for multiple batches/headers. Can someone help
me tweak this to work properly? The Saxon command line syntax is
commented at the end of the xsl.

transform_bus_cov_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="/">
<xsl:apply-templates select="root/record"/>
</xsl:template>

<xsl:template match="record">
<xsl:value-of select="$head"/>
<xsl:for-each select="*">
<xsl:value-of select="concat(., $delim)"/>
</xsl:for-each>
<xsl:value-of select="$nl"/>
</xsl:template>

</xsl:stylesheet>

<!-- java com.icl.saxon.StyleSheet -o trans_cidcov1.dat
trans_cidcov1.xml transform_bus_cov_to_tab_delim.xsl -->

Here is my test data input file trans_cidcov1.xml:

<?xml version="1.0" ?>
<root>
<header>
<driver_id>DRIVER_ID_1</driver_id>
<vehicle_id>BUS_99</vehicle_id>
<duty_shift_id>AM</duty_shift_id>
<route_id>72X</route_id>
<cid_terminal_id>COV_1</cid_terminal_id>
</header>
<record>
<date_time>2003/12/10.8:10</date_time>
<tag_id>TAG_ID_1</tag_id>
<stop_location_id>BUS_STOP_1</stop_location_id>
<fare_type_cd>L</fare_type_cd>
<blacklist_cd />
</record>
<record>
<date_time>2003/12/10.8:10</date_time>
<tag_id>TAG_ID_3</tag_id>
<stop_location_id>BUS_STOP_1</stop_location_id>
<fare_type_cd>L</fare_type_cd>
<blacklist_cd />
</record>
<record>
<date_time>2003/12/10.8:30</date_time>
<tag_id>TAG_ID_5</tag_id>
<stop_location_id>BUS_STOP_2</stop_location_id>
<fare_type_cd>R</fare_type_cd>
<blacklist_cd />
</record>
<record>
<date_time>2003/12/10.8:30</date_time>
<tag_id>TAG_ID_5</tag_id>
<stop_location_id>BUS_STOP_2</stop_location_id>
<fare_type_cd>R</fare_type_cd>
<blacklist_cd />
</record>
<record>
<date_time>2003/12/10.8:45</date_time>
<tag_id>TAG_ID_4</tag_id>
<stop_location_id>BUS_STOP_3</stop_location_id>
<fare_type_cd>L</fare_type_cd>
<blacklist_cd>I</blacklist_cd>
</record>
<record>
<date_time>2003/12/10.10:00</date_time>
<tag_id>TAG_ID_2</tag_id>
<stop_location_id>BUS_STOP_4</stop_location_id>
<fare_type_cd>E</fare_type_cd>
<blacklist_cd />
</record>
<record>
<date_time>2003/12/10.10:10</date_time>
<tag_id>TAG_ID_6</tag_id>
<stop_location_id>BUS_STOP_4</stop_location_id>
<fare_type_cd>L</fare_type_cd>
<blacklist_cd />
</record>
<record>
<date_time>2003/12/10.11:20</date_time>
<tag_id>TAG_ID_1</tag_id>
<stop_location_id>BUS_STOP_5</stop_location_id>
<fare_type_cd>L</fare_type_cd>
<blacklist_cd />
</record>
<record>
<date_time>2003/12/10.11:22</date_time>
<tag_id>TAG_ID_7</tag_id>
<stop_location_id>BUS_STOP_5</stop_location_id>
<fare_type_cd>L</fare_type_cd>
<blacklist_cd>I</blacklist_cd>
</record>
<header>
<driver_id>DRIVER_ID_1</driver_id>
<vehicle_id>BUS_1</vehicle_id>
<duty_shift_id>AM</duty_shift_id>
<route_id>72X</route_id>
<cid_terminal_id>COV_1</cid_terminal_id>
</header>
<record>
<date_time>2003/12/10.8:10</date_time>
<tag_id>TAG_ID_1</tag_id>
<stop_location_id>BUS_STOP_1</stop_location_id>
<fare_type_cd>L</fare_type_cd>
<blacklist_cd />
</record>
<record>
<date_time>2003/12/10.8:10</date_time>
<tag_id>TAG_ID_3</tag_id>
<stop_location_id>BUS_STOP_1</stop_location_id>
<fare_type_cd>L</fare_type_cd>
<blacklist_cd />
</record>
<record>
<date_time>2003/12/10.8:30</date_time>
<tag_id>TAG_ID_5</tag_id>
<stop_location_id>BUS_STOP_2</stop_location_id>
<fare_type_cd>R</fare_type_cd>
<blacklist_cd />
</record>
<record>
<date_time>2003/12/10.8:30</date_time>
<tag_id>TAG_ID_5</tag_id>
<stop_location_id>BUS_STOP_2</stop_location_id>
<fare_type_cd>R</fare_type_cd>
<blacklist_cd />
</record>
<record>
<date_time>2003/12/10.8:45</date_time>
<tag_id>TAG_ID_4</tag_id>
<stop_location_id>BUS_STOP_3</stop_location_id>
<fare_type_cd>L</fare_type_cd>
<blacklist_cd>I</blacklist_cd>
</record>
<record>
<date_time>2003/12/10.10:00</date_time>
<tag_id>TAG_ID_2</tag_id>
<stop_location_id>BUS_STOP_4</stop_location_id>
<fare_type_cd>E</fare_type_cd>
<blacklist_cd />
</record>
<record>
<date_time>2003/12/10.10:10</date_time>
<tag_id>TAG_ID_6</tag_id>
<stop_location_id>BUS_STOP_4</stop_location_id>
<fare_type_cd>L</fare_type_cd>
<blacklist_cd />
</record>
<record>
<date_time>2003/12/10.11:20</date_time>
<tag_id>TAG_ID_1</tag_id>
<stop_location_id>BUS_STOP_5</stop_location_id>
<fare_type_cd>L</fare_type_cd>
<blacklist_cd />
</record>
<record>
<date_time>2003/12/10.11:22</date_time>
<tag_id>TAG_ID_7</tag_id>
<stop_location_id>BUS_STOP_5</stop_location_id>
<fare_type_cd>L</fare_type_cd>
<blacklist_cd>I</blacklist_cd>
</record>
</root>

Thanks for your help.
Jul 20 '05 #1
0 1543

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

Similar topics

11
2732
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do...
1
7306
by: David Horowitz | last post by:
Hi folks. I need to create a report that has a Group Header that pulls certain data from the Detail section. It's something like this: +--Report---------------------------------------- |...
0
1766
by: LemonHead | last post by:
I have a report with a header and 2 sub-reports in the detail section. When I select "Repeat Section" to "Yes" in the main report, the header repeats multiple times with nothing else on the page. ...
4
2919
by: LF | last post by:
Hello, I have a database with a table of projects and a table of tasks (each project can have multiple tasks). I have a report that has a group header for the project name, etc., and then the...
8
1300
by: FuzzyLogik | last post by:
I am trying to make a logical link list, <ul> <li></li> </ul> But my sections have headers and footers. How do I do this? Example:
3
1591
by: abolos | last post by:
Hello all, I have a query with the following code: SELECT tblData.Name FROM tblData WHERE (((tblData.Talk) Like "*" & !! & "*")); The text30 is in the header of the form and not in its...
8
1655
by: JRough | last post by:
What is the purpose of caching in the header below? I used something like this for downloading a detail page to Excel but in this example it looks like it is for cache control? Why would you...
3
1716
by: geraldjr30 | last post by:
hi, i have the following, which lists days of the week, and records associated with each of them from an MS Access table. i would like to know how to display the count of the records associated...
0
7161
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...
0
7384
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,...
0
7539
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...
1
7101
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...
0
5686
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,...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1596
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 ...
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
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...

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.