match muliple header records to associated detail records

Discussion in 'XML' started by Luke Airig, Dec 31, 2003.

  1. Luke Airig

    Luke Airig Guest

    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:eek:utput method="text"/>

    <xsl:variable name="delim" select="' '"/> <!-- tab -->
    <xsl:variable name="nl" select="'
    '"/> <!-- 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.
     
    Luke Airig, Dec 31, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ying

    muliple datagrids on one page.

    Ying, Oct 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    392
  2. Darrel

    updating muliple records

    Darrel, Oct 29, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    454
    Darrel
    Oct 30, 2004
  3. Arun Kumar Menon

    Master Detail detail

    Arun Kumar Menon, Aug 6, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    209
    Arun Kumar Menon
    Aug 6, 2003
  4. Frederik Borg

    ASp.net data binding: Master-detail-detail

    Frederik Borg, Jun 9, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    373
    Frederik Borg
    Jun 9, 2006
  5. Tyler Lynch

    Inserting from DetailsView and associated Child Records

    Tyler Lynch, Dec 7, 2007, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    242
    Phil H
    Dec 8, 2007
Loading...

Share This Page