Looking for a way to output CSV
-
I'm working on an XSL stylesheet to transform data from XML to CSV. (With .net 2.0) I have everything working except being able to double-up or escape quote characters within strings. What I understand from the book I have I would need to use EXSLT; A) str:replace B) str:split and str:concat C) regexp:replace I don't want to have to install anything "extra" onto client systems. What other options are there?
-
I'm working on an XSL stylesheet to transform data from XML to CSV. (With .net 2.0) I have everything working except being able to double-up or escape quote characters within strings. What I understand from the book I have I would need to use EXSLT; A) str:replace B) str:split and str:concat C) regexp:replace I don't want to have to install anything "extra" onto client systems. What other options are there?
Alright, I got it working by using a param with my template and calling it recursively as required.
<xsl:template match="*">
<xsl:param name="Cont" select="."/>
<xsl:if test="@Null='false'">
xsl:text"</xsl:text><xsl:value-of select="substring-before(concat($Cont,'"'),'"')"/>xsl:text"</xsl:text>
<xsl:if test="contains($Cont,'"')">
<xsl:apply-templates select=".">
<xsl:with-param name="Cont" select="substring-after($Cont,'"')"/>
</xsl:apply-templates>
</xsl:if>
</xsl:if>
</xsl:template>Note the use of concat() in the call to substring-before(). Here the param is named "Cont" and you can think of it as meaning either "contents" or "continuance". Given an initial value of:
aaa "bbb" ccc
1) Output"aaa "
2) Recurse withbbb" ccc
3) Output"bbb"
4) Recurse withccc
5) Output" ccc"
Result:"aaa ""bbb"" ccc"
I would appreciate any thoughts on this technique.