title: Create Excel (SpeadsheetML) output with XSLT
body: <p>I have this XML file and I want to create an XSL file to convert it to Excel. Each row should represent a logo. The columns will be the key attributes like color, id, description plus any other key for other logos. </p>
  
  <pre><code>&lt;Top&gt;
    &lt;logo&gt;
      &lt;field key="id"&gt;172-32-1176&lt;/field&gt;
      &lt;field key="color"&gt;Blue&lt;/field&gt;
      &lt;field key="description"&gt;&lt;p&gt;Short Description&lt;/p&gt;&lt;/field&gt;
      &lt;field key="startdate"&gt;408 496-7223&lt;/field&gt;
    &lt;/logo&gt;
    &lt;logo&gt;
      &lt;field key="id"&gt;111-111-111&lt;/field&gt;
      &lt;field key="color"&gt;Red&lt;/field&gt;
    &lt;/logo&gt;
    &lt;!-- ... --&gt;    
  &lt;/Top&gt;
  </code></pre>
  
  <p>The XSL file is something like this:</p>
  
  <pre><code>&lt;xsl:stylesheet 
    version="1.0"
    xmlns="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:user="urn:my-scripts"
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
  &gt; 
  
    &lt;xsl:template match="/"&gt;
      &lt;Workbook 
        xmlns="urn:schemas-microsoft-com:office:spreadsheet"
        xmlns:o="urn:schemas-microsoft-com:office:office"
        xmlns:x="urn:schemas-microsoft-com:office:excel"
        xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
        xmlns:html="http://www.w3.org/TR/REC-html40"
      &gt;
        &lt;xsl:apply-templates/&gt;
      &lt;/Workbook&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="/*"&gt;  
      &lt;Worksheet&gt;
        &lt;xsl:attribute name="ss:Name"&gt;
          &lt;xsl:value-of&gt; select="local-name(/*)"/&gt;
        &lt;/xsl:attribute&gt;
        &lt;Table x:FullColumns="1" x:FullRows="1"&gt;
          &lt;Row&gt;
            &lt;xsl:for-each select="*/*"&gt;
              &lt;Cell&gt;
                &lt;Data ss:Type="String"&gt;
                  &lt;xsl:value-of select="@key"/&gt;
                &lt;/Data&gt;
              &lt;/Cell&gt;
            &lt;/xsl:for-each&gt;
          &lt;/Row&gt;
          &lt;xsl:apply-templates/&gt;
        &lt;/Table&gt;
      &lt;/Worksheet&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="/*/*"&gt;
      &lt;Row&gt;
        &lt;xsl:apply-templates/&gt;
      &lt;/Row&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="/*/*/*"&gt;
      &lt;Cell&gt;
        &lt;Data ss:Type="String"&gt;
          &lt;xsl:value-of select="."/&gt;
        &lt;/Data&gt;
      &lt;/Cell&gt;
      &lt;!-- &lt;xsl:apply-templates/&gt; --&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>But data are not correctly placed under the columns and column names are repeating. How can this be done?
  The columns could be in any order and also column stardate should be empty for second  row in excel. Similarly for more .</p>