Monday, October 19, 2009
An XSLT to convert an XML file into a CSV
<xsl:stylesheet version="1.0
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<!-- IF_THE_PIVOT_IS_A_SUBTYPE_IT_NEEDS_TO_GO_IN_HERE -->
>
<xsl:output method="text"/>"
<xsl:template match="//PIVOT_GOES_IN_HERE">
<xsl:apply-templates select="*" />
<xsl:text>
</xsl:text>
</xsl:template>"
<xsl:template match="//PIVOT_GOES_IN_HERE//*">
<xsl:choose>
<xsl:when test="count(child::*) > 0">
<xsl:apply-templates select="*" />
</xsl:when>
<xsl:otherwise>
<xsl:text>"</xsl:text>
<xsl:value-of select="."/>
<xsl:text>"</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="position() != last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Labels: programming
Subscribe to Posts [Atom]