[xsl] XML To CSV

Subject: [xsl] XML To CSV
From: <ashushujev@xxxxxxxxxxxx>
Date: Wed, 4 Aug 2004 19:18:01 +0200
Hi Roy,

Thanks for the stylesheet, it works fine. I also managed to extract
default MSIE stylesheet and use as well. Although I have another
problem considering the following XML feed with variable length
infoset:

XML:
<?xml version="1.0"?>
<Data>
  <Account>
    <AccountNumber>1000748</AccountNumber>
    <SequenceNo>1</SequenceNo>
    <AccountBalance>1052.35</AccountBalance>
    <Name>
      <CitizenNameTitle>Mr</CitizenNameTitle>
      <CitizenNameForename>Joe</CitizenNameForename>
      <CitizenNameSurname>Bloggs</CitizenNameSurname>
    </Name>
  </Account>
  <Account>
    <AccountNumber>1000741</AccountNumber>
    <SequenceNo>1</SequenceNo>
    <AccountBalance>800.53</AccountBalance>
    <Name>
      <CitizenNameForename>John</CitizenNameForename>
      <CitizenNameSurname>Doe</CitizenNameSurname>
    </Name>
  </Account>
</Data>

XSL:
<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";  
version="1.0"> 
    <xsl:output method="text"/> 

    <xsl:template match="/"> 
       <xsl:apply-templates select="//Account[1]/descendant::*" /> 
    </xsl:template> 

    <xsl:template match="*"> 
       <xsl:if test = "normalize-space(text())!=''" > 
          <xsl:value-of select = "." /> 
          <xsl:if test = "not(position()=last())" > 
             <xsl:text > ,</xsl:text>
          </xsl:if> 
       </xsl:if> 
    </xsl:template> 
</xsl:stylesheet>

Current output:
1000748,1,1052.35,Mr,Joe,Bloggs,1000741,1,800.53,John,Doe

Required output:
1000748,1,1052.35,Mr,Joe,Bloggs
1000741,1,800.53,,John,Doe


Any advice much appreciated.


Andrew

Current Thread