title: How do i change XML to XML using XSLT
body: <p>Hi im trying to change my XML document using XSLT. I have tried to follow some of the other threads about the topic on Stack Overflow, but i can't get it working. My XML file is a database export and it's the only way i can export all my data at once, with the software i'm using. But the layout of the exported data won't work in the program i am extracting the file too, so i need to change the layout of the XML before i import it to the new program.</p>
  <p>This is my original XML.</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;Log&gt;
    &lt;DataSource&gt;test&lt;/DataSource&gt;
    &lt;SQLStatement&gt;SELECT * FROM test_elementer WHERE country='FR';&lt;/SQLStatement&gt;
    &lt;SQLStatementResult&gt;Success&lt;/SQLStatementResult&gt;
    &lt;SQLStatementValue&gt;
      &lt;Row&gt;
        &lt;Column Name=&quot;id&quot; DataType=&quot;INTEGER&quot;&gt;1&lt;/Column&gt;
        &lt;Column Name=&quot;country&quot; DataType=&quot;STRING&quot;&gt;FR&lt;/Column&gt;
        &lt;Column Name=&quot;city&quot; DataType=&quot;STRING&quot;&gt;Lyon&lt;/Column&gt;
        &lt;Column Name=&quot;windows_1000x1000&quot; DataType=&quot;INTEGER&quot;&gt;1&lt;/Column&gt;
        &lt;Column Name=&quot;windows_1000x750&quot; DataType=&quot;INTEGER&quot;&gt;2&lt;/Column&gt;
        &lt;Column Name=&quot;windows_1250x1250&quot; DataType=&quot;INTEGER&quot;&gt;3&lt;/Column&gt;
        &lt;Column Name=&quot;street_700x1000&quot; DataType=&quot;INTEGER&quot;&gt;4&lt;/Column&gt;
      &lt;/Row&gt;
      &lt;Row&gt;
        &lt;Column Name=&quot;id&quot; DataType=&quot;INTEGER&quot;&gt;2&lt;/Column&gt;
        &lt;Column Name=&quot;country&quot; DataType=&quot;STRING&quot;&gt;FR&lt;/Column&gt;
        &lt;Column Name=&quot;city&quot; DataType=&quot;STRING&quot;&gt;Herblay&lt;/Column&gt;
        &lt;Column Name=&quot;windows_1000x1000&quot; DataType=&quot;INTEGER&quot;&gt;4&lt;/Column&gt;
        &lt;Column Name=&quot;windows_1000x750&quot; DataType=&quot;INTEGER&quot;&gt;2&lt;/Column&gt;
        &lt;Column Name=&quot;windows_1250x1250&quot; DataType=&quot;INTEGER&quot;&gt;3&lt;/Column&gt;
        &lt;Column Name=&quot;street_700x1000&quot; DataType=&quot;INTEGER&quot;&gt;1&lt;/Column&gt;
      &lt;/Row&gt;
      &lt;Row&gt;
        &lt;Column Name=&quot;id&quot; DataType=&quot;INTEGER&quot;&gt;3&lt;/Column&gt;
        &lt;Column Name=&quot;country&quot; DataType=&quot;STRING&quot;&gt;FR&lt;/Column&gt;
        &lt;Column Name=&quot;city&quot; DataType=&quot;STRING&quot;&gt;Nantes&lt;/Column&gt;
        &lt;Column Name=&quot;windows_1000x1000&quot; DataType=&quot;INTEGER&quot;&gt;5&lt;/Column&gt;
        &lt;Column Name=&quot;windows_1000x750&quot; DataType=&quot;INTEGER&quot;&gt;3&lt;/Column&gt;
        &lt;Column Name=&quot;windows_1250x1250&quot; DataType=&quot;INTEGER&quot;&gt;1&lt;/Column&gt;
        &lt;Column Name=&quot;street_700x1000&quot; DataType=&quot;INTEGER&quot;&gt;4&lt;/Column&gt;
      &lt;/Row&gt;
    &lt;/SQLStatementValue&gt;
  &lt;/Log&gt;
  </code></pre>
  <p>I need to convert this XML to the following:</p>
  <pre><code>&lt;data&gt;
    &lt;store&gt;
      &lt;id&gt;1&lt;/id&gt;
      &lt;country&gt;FR&lt;/country&gt;
      &lt;city&gt;Lyon&lt;/city&gt;
      &lt;windows_1000x1000&gt;1&lt;/windows_1000x1000&gt;
      &lt;windows_1000x750&gt;2&lt;/windows_1000x750&gt;
      &lt;windows_1250x1250&gt;3&lt;/windows_1250x1250&gt;
      &lt;windows_700x1000&gt;4&lt;/windows_700x1000&gt;
    &lt;/store&gt;
    &lt;store&gt;
      &lt;id&gt;2&lt;/id&gt;
      &lt;country&gt;FR&lt;/country&gt;
      &lt;city&gt;Herblay&lt;/city&gt;
      &lt;windows_1000x1000&gt;4&lt;/windows_1000x1000&gt;
      &lt;windows_1000x750&gt;2&lt;/windows_1000x750&gt;
      &lt;windows_1250x1250&gt;3&lt;/windows_1250x1250&gt;
      &lt;windows_700x1000&gt;1&lt;/windows_700x1000&gt;
    &lt;/store&gt;
    &lt;store&gt;
      &lt;id&gt;3&lt;/id&gt;
      &lt;country&gt;FR&lt;/country&gt;
      &lt;city&gt;Nantes&lt;/city&gt;
      &lt;windows_1000x1000&gt;5&lt;/windows_1000x1000&gt;
      &lt;windows_1000x750&gt;3&lt;/windows_1000x750&gt;
      &lt;windows_1250x1250&gt;1&lt;/windows_1250x1250&gt;
      &lt;windows_700x1000&gt;4&lt;/windows_700x1000&gt;
    &lt;/store&gt;
  &lt;/data&gt;
  </code></pre>
  <p>This is the XSL code i tried:</p>
  <pre><code>&lt;xsl:transform xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; version=&quot;2.0&quot;&gt;
      &lt;xsl:output indent=&quot;yes&quot;/&gt;
  
      &lt;xsl:template match=&quot;/&quot;&gt;
          &lt;data&gt;
              &lt;xsl:apply-templates select=&quot;Log/SQLStatementValue/Row&quot; /&gt; 
          &lt;/data&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match=&quot;Row&quot;&gt;
          &lt;store&gt;
              &lt;xsl:apply-templates select=&quot;Column[@name = 'id']&quot;/&gt;
              &lt;xsl:apply-templates select=&quot;Column[@name = 'country']&quot;/&gt;
              &lt;xsl:apply-templates select=&quot;Column[@name = 'city']&quot;/&gt;
              &lt;xsl:apply-templates select=&quot;Column[@name = 'windows_1000x1000']&quot;/&gt;
              &lt;xsl:apply-templates select=&quot;Column[@name = 'windows_1000x750']&quot;/&gt;
              &lt;xsl:apply-templates select=&quot;Column[@name = 'windows_1250x1250']&quot;/&gt;
              &lt;xsl:apply-templates select=&quot;Column[@name = 'street_700x1000']&quot;/&gt;
          &lt;/store&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match=&quot;Column[@name = 'id']&quot;&gt;
          &lt;id&gt;
          &lt;xsl:value-of select=&quot;.&quot;/&gt;
          &lt;/id&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match=&quot;Column[@name = 'country']&quot;&gt;
          &lt;country&gt;
          &lt;xsl:value-of select=&quot;.&quot;/&gt;
          &lt;/country&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match=&quot;Column[@name = 'city']&quot;&gt;
          &lt;city&gt;
          &lt;xsl:value-of select=&quot;.&quot;/&gt;
          &lt;/city&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match=&quot;Column[@name = 'windows_1000x1000']&quot;&gt;
          &lt;windows_1000x1000&gt;
          &lt;xsl:value-of select=&quot;.&quot;/&gt;
          &lt;/windows_1000x1000&gt;
      &lt;/xsl:template&gt;
      
      &lt;xsl:template match=&quot;Column[@name = 'windows_1000x750']&quot;&gt;
          &lt;windows_1000x750&gt;
          &lt;xsl:value-of select=&quot;.&quot;/&gt;
          &lt;/windows_1000x750&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match=&quot;Column[@name = 'windows_1250x1250']&quot;&gt;
          &lt;windows_1250x1250&gt;
          &lt;xsl:value-of select=&quot;.&quot;/&gt;
          &lt;/windows_1250x1250&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match=&quot;Column[@name = 'street_700x1000']&quot;&gt;
          &lt;street_700x1000&gt;
          &lt;xsl:value-of select=&quot;.&quot;/&gt;
          &lt;/street_700x1000&gt;
      &lt;/xsl:template&gt;
  
  &lt;/xsl:transform&gt;
  </code></pre>