Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Insert a CRLF when transforming XML into text

From: SavvoulidisIordanis@-----------.---------.---
To: NULL
Date: 1/3/2009 4:40:00 PM
I want to create a CSV (text) file out of a XML file, so it can be bulk 
copied into SQLServer. How can I insert a CRLF char when I'm done converting 
every record into its corresponding CSV?
The XML file I use, depicts master and detail records. In the CSV, I want to 
have each of the master record and its detail records in one line, no matter 
how many detail records there are for each master. Master fields are 
separated by semicolon (;) and the details are separated by caret sign (^). 
XML follows:

<Section>  <!-- master 1-->
        <BetStartDate>4/6/2009</BetStartDate>
        <BetEndDate>4/8/2009</BetEndDate>
        <Event>  <!-- details -->
            <Code>111</Code>
            <Description>TEAM 1</Description>
            <Apodosi>10,00</Apodosi>
        </Event>
        <Event>
            <Code>112</Code>
            <Description>TEAM 2 </Description>
            <Apodosi>20,00</Apodosi>
        </Event>
</Section>
<Section>  <!-- master 2-->
        <BetStartDate>12/12/2008</BetStartDate>
        <BetEndDate>16/12/2008</BetEndDate>
        <Event>  <!-- details -->
            <Code>211</Code>
            <Description>TEAM 3</Description>
            <Apodosi>5,00</Apodosi>
        </Event>
        <Event>
            <Code>212</Code>
            <Description>TEAM 4</Description>
            <Apodosi>4,00</Apodosi>
        </Event>
        <Event>
            <Code>213</Code>
            <Description>TEAM 5</Description>
            <Apodosi>7,00</Apodosi>
        </Event>
</Section>

I want to get:
4/6/2009;4/8/2009^111^TEAM 1^10,00^112^TEAM 2^20,00
12/12/2008;16/12/2008^211^TEAM 3^5,00^212^TEAM 4^4,00^213^TEAM 5^7,00

I use the following template, which works, except it outputs only one line 
that includes everything. I want to have a CRLF after 20,00 as displayed 
above.

<xsl:template match="/">
<xsl:for-each select="Section">
<xsl:value-of select="BetStartDate" />;<xsl:value-of 
select="BetEndDate"/><xsl:for-each select="Event">^<xsl:value-of 
select="Code"/>^<xsl:value-of select="Description"/>^<xsl:value-of 
select="Apodosi"/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>

TIA



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent