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>&#x0D;&#x0A;</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:


Comments: Post a Comment



Links to this post:

Create a Link



<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]