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, '"' )">
<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, '
', '')"/>
</xsl:variable>
<xsl:value-of select="concat('"', $newval, '"')" />
<xsl:if test="position() != last()"><xsl:text>,</xsl:text></xsl:if>
</xsl:for-each>
<xsl:text>
</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, '"' )" />
<xsl:text>""</xsl:text>
<xsl:variable name="substring_after_first_quote" select="substring-after( $string, '"' )" />
<xsl:choose>
<xsl:when test="not( contains( $substring_after_first_quote, '"' ) )">
<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.