xsl-list
[Top] [All Lists]

Re: xml to csv

2005-11-21 03:34:43

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="text"/>

<xsl:template match="root">
<xsl:apply-templates select="*[last()]"/>
</xsl:template>

<xsl:template match="root/*">
<xsl:param name="l"/>
<xsl:variable name="here" select="."/>
<xsl:variable name="sep">
<xsl:if test="following-sibling::*">, </xsl:if>
</xsl:variable>
<xsl:for-each select="descendant-or-self::*[not(*)]">
<xsl:choose>
<xsl:when test="$here/preceding-sibling::*">
<xsl:apply-templates select="$here/preceding-sibling::*[1]">
  <xsl:with-param name="l" select="concat(.,$sep,$l)"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
  <xsl:value-of select="concat(.,$sep,$l,'&#10;')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>



</xsl:stylesheet>


$ saxon bb.xml bb.xsl
a, bb1, ccc1, dd1
a, bb2, ccc1, dd1
a, bb3, ccc1, dd1
a, bb4, ccc1, dd1
a, bb1, ccc2, dd1
a, bb2, ccc2, dd1
a, bb3, ccc2, dd1
a, bb4, ccc2, dd1
a, bb1, ccc1, dd2
a, bb2, ccc1, dd2
a, bb3, ccc1, dd2
a, bb4, ccc1, dd2
a, bb1, ccc2, dd2
a, bb2, ccc2, dd2
a, bb3, ccc2, dd2
a, bb4, ccc2, dd2


________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>