Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-17-2008, 10:08 PM   PM User | #1
dulatoag
New Coder

 
Join Date: Dec 2002
Location: New York State
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
dulatoag is an unknown quantity at this point
double line breaks in xslt csv export!!

Hey all:

A very simple xslt file here that I'm using to export FileMaker data into a csv file. Works great, but it puts in two line breaks after each row. So when I pull it into excel, I have values on every other row, with a blank in between. Can't figure it out to save my life. Here's the code:
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet 
	version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:fm="http://www.filemaker.com/fmpxmlresult" 
	exclude-result-prefixes="fm">
	<xsl:output method="text" version="1.0" encoding="utf-8" indent="no" />
	<xsl:template match="/">
<!-- Header line, inserted only once; if not desired, remove -->
<xsl:text>
All of my column headers here ...
</xsl:text>
<!-- LOOP THROUGH THE RECORDS (as ROW) -->

<xsl:for-each select="fm:FMPXMLRESULT/fm:RESULTSET/fm:ROW">
<!-- LOOP THROUGH THE FIELDS (as COL/DATA) -->
<xsl:for-each select="fm:COL/fm:DATA">
<xsl:variable name="fmdata">
<xsl:value-of select="."/>
</xsl:variable>
<xsl:variable name="newData">
  <xsl:choose>
    <xsl:when test="contains( $fmdata, '&quot;' )">

                      <xsl:call-template name="escape_quotes">
                     <xsl:with-param name="string" select="$fmdata" />
                 </xsl:call-template>
    </xsl:when>
    <xsl:otherwise><xsl:value-of select="$fmdata"/></xsl:otherwise>
  </xsl:choose>
</xsl:variable>


             <xsl:variable name="newval">
               <xsl:value-of select="translate($newData, '&#xA;', '')"/>
             </xsl:variable>

				<xsl:value-of select="concat('&#x22;', $newval, '&#x22;')" />
				<xsl:if test="position() != last()"><xsl:text>,</xsl:text></xsl:if>
			</xsl:for-each>
			<xsl:text>&#xA;</xsl:text>
		</xsl:for-each>
		             <xsl:variable name="thissheet">
               <xsl:value-of select="." />
             </xsl:variable>
	</xsl:template>

 <xsl:template name="escape_quotes">
        <xsl:param name="string" />

       <xsl:value-of select="substring-before( $string, '&quot;' )" />
        <xsl:text>""</xsl:text>
        <xsl:variable name="substring_after_first_quote" select="substring-after( $string, '&quot;' )" />
        <xsl:choose>
            <xsl:when test="not( contains( $substring_after_first_quote, '&quot;' ) )">
                <xsl:value-of select="$substring_after_first_quote" />
            </xsl:when>
            <xsl:otherwise>
        <!-- The substring after the first quote contains a quote.
           So, we call ourself recursively to escape the quotes
           in the substring after the first quote.
      -->
                <xsl:call-template name="escape_quotes">
                    <xsl:with-param name="string" select="$substring_after_first_quote"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>
Any help would be greatly appreciated. Thanks.

Last edited by Alex Vincent; 12-18-2008 at 12:56 AM.. Reason: adding code tags
dulatoag is offline   Reply With Quote
Old 12-24-2008, 05:18 PM   PM User | #2
KeithLawless
New to the CF scene

 
Join Date: Dec 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
KeithLawless is an unknown quantity at this point
Would it be possible to post the source XML file you are using? Also, what tool are using to perform the transformation?

I loaded your XSLT into XMLSpy, and downloaded a sample XML file from the Filemaker site at http://www.filemaker.com/help/12-Import%20export34.html.

The output was what you are expecting - one line of CSV data per line, no extra line-breaks. The only thing I saw out of whack was an extra line feed at the end of the file, resulting in a blank line at the end of the file. Excel didn't seem to mind having that line there.
KeithLawless is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:48 PM.


Advertisement
Log in to turn off these ads.