Advertisement

12.21.2003 at 05:59PM PST, ID: 20831953
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

Concatenate Header contents to each detail record and write out flat file

Asked by luke_airig in Extensible Markup Language (XML)

Tags: , , ,

I have the following xml file that I need to transform to a tab-delimited flat file:

<?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>
   <longitude>-105.111111</longitude>
   <latitude>39.111111</latitude>
   <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>
   <longitude>-105.222222</longitude>
   <latitude>39.222222</latitude>
   <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>
</root>

I need to concatenate the <header> fields to the front of each <record> as follows:

driver_id_from_trans vehicle_id_from_trans duty_shift_id_from_trans route_id_from_trans cid_terminal_id_from_trans -105.111111 39.111111 2003/12/10.16:08 tag_id_from_trans_1 stop_location_id_from_trans_1 fare_type_cd_from_trans_1 blacklist_cd_from_trans_1
driver_id_from_trans vehicle_id_from_trans duty_shift_id_from_trans route_id_from_trans cid_terminal_id_from_trans -105.222222 39.222222 2003/12/10.16:18 tag_id_from_trans_4 stop_location_id_from_trans_4 fare_type_cd_from_trans_4 blacklist_cd_from_trans_4

Here is the xsl stylesheet that I hoped would work, but no luck:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text" />
  <xsl:template match="/" >
    <xsl:param name="delim" select="'&#x9;'"/>   <!-- tab     -->
    <xsl:param name="nl"    select="'&#xA;'"/>   <!-- newline -->

    <xsl:for-each select="root/header">
      <xsl:value-of select="normalize-space(driver_id)"/>
      <xsl:value-of select="$delim"/>

      <xsl:value-of select="normalize-space(vehicle_id)"/>
      <xsl:value-of select="$delim"/>

      <xsl:value-of select="normalize-space(duty_shift_id)"/>
      <xsl:value-of select="$delim"/>

      <xsl:value-of select="normalize-space(route_id)"/>
      <xsl:value-of select="$delim"/>

      <xsl:value-of select="normalize-space(cid_terminal_id)"/>
      <xsl:value-of select="$delim"/>

      <xsl:for-each select="root/record">
        <xsl:value-of select="normalize-space(longitude)"/>
        <xsl:value-of select="$delim"/>

        <xsl:value-of select="normalize-space(latitude)"/>
        <xsl:value-of select="$delim"/>

        <xsl:value-of select="normalize-space(date_time)"/>
        <xsl:value-of select="$delim"/>

        <xsl:value-of select="normalize-space(tag_id)"/>
        <xsl:value-of select="$delim"/>

        <xsl:value-of select="normalize-space(stop_location_id)"/>
        <xsl:value-of select="$delim"/>

        <xsl:value-of select="normalize-space(fare_type_cd)"/>
        <xsl:value-of select="$delim"/>

        <xsl:value-of select="normalize-space(blacklist_cd)"/>
        <xsl:value-of select="$delim"/>

        <xsl:value-of select="$nl"/>               <!-- newline -->

      </xsl:for-each>
    </xsl:for-each>

  </xsl:template>
</xsl:stylesheet>

Can someone tweak this for me to get it to work?

TIA

Start Free Trial
[+][-]12.21.2003 at 06:57PM PST, ID: 9983041

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]12.21.2003 at 10:32PM PST, ID: 9983615

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]12.22.2003 at 01:45PM PST, ID: 9987752

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.22.2003 at 10:58PM PST, ID: 9989791

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Extensible Markup Language (XML)
Tags: concatenate, header, file, flat
Sign Up Now!
Solution Provided By: petiex
Participating Experts: 3
Solution Grade: A
 
 
[+][-]12.23.2003 at 08:40AM PST, ID: 9992020

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.29.2003 at 10:41PM PST, ID: 10014772

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]01.05.2004 at 12:03PM PST, ID: 10046463

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.20.2004 at 09:06AM PST, ID: 10156317

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32