title: convert xml document to comma delimited (CSV) file using xslt stylesheet
body: <p>I need some assistance converting an xml document to a CSV file using an xslt stylesheet. I am trying to use the following xsl and I can't seem to get it right. I want my comma delimited file to include column headings, followed by the data. My biggest issues are removing the final comma after the last item and inserting a carriage return so each group of data appears on a separate line. I have been using XML Notepad.</p>
  
  <p>
  
        </p>
  
  <pre><code>  &lt;xsl:template match="/"&gt;
          &lt;xsl:element name="table"&gt;
                &lt;xsl:apply-templates select="/*/*[1]" mode="header" /&gt;
                &lt;xsl:apply-templates select="/*/*" mode="row" /&gt;
          &lt;/xsl:element&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="*" mode="header"&gt;
          &lt;xsl:element name="tr"&gt;
                &lt;xsl:apply-templates select="./*" mode="column" /&gt;
          &lt;/xsl:element&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="*" mode="row"&gt;
          &lt;xsl:element name="tr"&gt;
                &lt;xsl:apply-templates select="./*" mode="node" /&gt;
          &lt;/xsl:element&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="*" mode="column"&gt;
          &lt;xsl:element name="th"&gt;
                &lt;xsl:value-of select="translate(name(.),'qwertyuiopasdfghjklzxcvbnm_','QWERTYUIOPASDFGHJKLZXCVBNM ')" /&gt;
          &lt;/xsl:element&gt;,
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="*" mode="node"&gt;
          &lt;xsl:element name="td"&gt;
                &lt;xsl:value-of select="." /&gt;
          &lt;/xsl:element&gt;,
    &lt;/xsl:template&gt; 
  </code></pre>
  
  <p></p>