[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Converting XML source to CSV output

Subject: RE: Converting XML source to CSV output
From: Mark Feblowitz <mfeblowitz@xxxxxxxxxxxxxxxx>
Date: Thu, 20 Sep 2001 10:41:11 -0400
xsl output text record
Perhaps an faq, but why is it that "concat" is used instead of merely
outputting the text as encountered and letting the output stream act as a de
facto concat?

Mark Feblowitz

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of
> Chris Pearson
> Sent: 19 September 2001 19:41
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Converting XML source to CSV output
>
>
> Hi all.  A novice question that I can't seem to locate a solution for
> ...  I have an XML source that I need to convert to a text delimited
> file.
>
> The xml source is:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <DATA>
>    <HEADER>
>       <RECORD_A value="Header1 Record A" />
>       <RECORD_B value="Header1 Record B" />
>       <RECORD_n value="Header1 Record n" />
>    </HEADER>
>    <BODY>
>       <BODY_RECORD_A value="Body1 Record A" />
>       <BODY_RECORD_B value="Body1 Record B" />
>       <BODY_RECORD_n value="Body1 Record n" />
>       <DETAIL>
>          <DET_RECORD_A value="Detail1 Record A" />
>          <DET_RECORD_B value="Detail1 Record B" />
>          <DET_RECORD_n value="Detail1 Record n" />
>       </DETAIL>
>       <DETAIL>
>          <DET_RECORD_A value="Detail2 Record A" />
>          <DET_RECORD_B value="Detail2 Record B" />
>          <DET_RECORD_n value="Detail2 Record n" />
>       </DETAIL>
>    </BODY>
>    <BODY>
>       <BODY_RECORD_A value="Body2 Record A" />
>       <BODY_RECORD_B value="Body2 Record B" />
>       <BODY_RECORD_n value="Body2 Record n" />
>       <DETAIL>
>          <DET_RECORD_A value="Detail3 Record A" />
>          <DET_RECORD_B value="Detail3 Record B" />
>          <DET_RECORD_n value="Detail3 Record n" />
>       </DETAIL>
>       <DETAIL>
>          <DET_RECORD_A value="Detail4 Record A" />
>          <DET_RECORD_B value="Detail4 Record B" />
>          <DET_RECORD_n value="Detail4 Record n" />
>       </DETAIL>
>    </BODY>
> </DATA>
>
> +++++++++++++++++++++++++++++++++++++++++++
>
> My stylesheet is:
>
> <?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" media-type="text/plain" />
> <xsl:strip-space elements="DATA HEADER BODY" />
>
> <xsl:template match="DATA">
>    <xsl:apply-templates />
> </xsl:template>
>
> <xsl:template match="HEADER">
>    <xsl:variable name="rec1" select="RECORD_A/@value" />
>    <xsl:variable name="rec2" select="RECORD_B/@value" />
>    <xsl:variable name="recn" select="RECORD_n/@value" />
>    <xsl:variable name="Head_Line"
>       select="concat ($rec1, ',', $rec2, ',', $recn, ',')" />
>    <xsl:value-of select="$Head_Line" />
>    <xsl:apply-templates />
> </xsl:template>
>
> <xsl:template match="BODY">
>    <xsl:variable name="bodya" select="BODY_RECORD_A/@value" />
>    <xsl:variable name="bodyb" select="BODY_RECORD_B/@value" />
>    <xsl:variable name="bodyn" select="BODY_RECORD_n/@value" />
>    <xsl:variable name="Body_Line"
>       select="concat ($bodya, ',', $bodyb, ',', $bodyn, ',')" />
>    <xsl:value-of select="$Body_Line" />
>    <xsl:apply-templates />
> </xsl:template>
>
> <xsl:template match="DETAIL">
>    <xsl:variable name="deta" select="DET_RECORD_A/@value" />
>    <xsl:variable name="detb" select="DET_RECORD_B/@value" />
>    <xsl:variable name="detn" select="DET_RECORD_n/@value" />
>    <xsl:variable name="Detail_Line"
>       select="concat ($deta, ',', $detb, ',', $detn)" />
>    <xsl:value-of select="$Detail_Line" />
>    <xsl:apply-templates />
> </xsl:template>
>
> </xsl:stylesheet>
>
> ++++++++++++++++++++++++++++++++++++++
>
> And, my output is:
>
> Header1 Record A,Header1 Record B,Header1 Record n,Body1
> Record A,Body1
> Record B,Body1 Record n,Detail1 Record A,Detail1 Record
> B,Detail1 Record
> n
>
>
>
>       Detail2 Record A,Detail2 Record B,Detail2 Record n
>
>
>
>       Body2 Record A,Body2 Record B,Body2 Record n,Detail3 Record
> A,Detail3 Record B,Detail3 Record n
>
>
>
>       Detail4 Record A,Detail4 Record B,Detail4 Record n
>
> ++++++++++++++++++++++++++++++++++++++
>
> What I want is:
>
> Header1 Record A,Header1 Record B,Header1 Record n,Body1
> Record A,Body1
> Record B,Body1 Record n,Detail1 Record A,Detail1 Record
> B,Detail1 Record
> n
> Header1 Record A,Header1 Record B,Header1 Record n,Body1
> Record A,Body1
> Record B,Body1 Record n,Detail2 Record A,Detail2 Record
> B,Detail2 Record
> n
> Header1 Record A,Header1 Record B,Header1 Record n,Body2
> Record A,Body2
> Record B,Body2 Record n,Detail3 Record A,Detail3 Record
> B,Detail3 Record
> n
> Header1 Record A,Header1 Record B,Header1 Record n,Body2
> Record A,Body2
> Record B,Body2 Record n,Detail4 Record A,Detail4 Record
> B,Detail4 Record
> n
>
> I'm having 2 issues:
>
> 1) How to repeat the header (and Body data) for detail records
> 2) How to format it without extra white space
>
> Is my approach flawed?  Any and all suggestions, comments,
> criticisms or
> random postulations welcomed.  Thanks in advance!
>
> Chris
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.