title: Flat XML to Unique Nested XML using XLST 1.0
body: <p>I'm trying to get the output from a filemaker database export into a form usable by a web application.  I've attempted to write an XLST (1.0) to do the transformation.  Filemaker output is essentially a spreadsheet (rows x columns), and I want to convert this based on relationships.  Essentially for every tank "Col[1]" I want data collected on a certain date "Col[2]" associated with this "Col[3]".</p>
  
  <p>Using XSLT, I've been able to get the unique dates, or the unique tanks, but not multiple dates for each tank.</p>
  
  <p>I've included my XLST, as well as a "simplified" version of what the input XML looks like, and what I'm hoping to get out.</p>
  
  <p>Many thanks in advance for any advise!</p>
  
  <p><strong>XLST so Far</strong></p>
  
  <pre><code>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fmp="http://www.filemaker.com/fmpxmlresult" version="1.0" exclude-result-prefixes="fmp"&gt;
  &lt;xsl:output method="xml" version="1.0" encoding="windows-1251" indent="yes"/&gt;
  
  &lt;xsl:key name="fishdate" match="fmp:ROW" use="fmp:COL[3]"/&gt;
  &lt;xsl:key name="tanknumber" match="fmp:ROW" use="fmp:COL[9]"/&gt;
  
  &lt;xsl:template match="/"&gt;
      &lt;fishroom&gt;
          &lt;xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[generate-id()=generate-id(key('tanknumber',fmp:COL[9]))]"&gt;
  
                  &lt;!-- &lt;xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[generate-id()=generate-id(key('fishdate',fmp:COL[3]))]"&gt; --&gt;
                          &lt;date&gt; &lt;xsl:value-of select="fmp:COL[3]/fmp:DATA"/&gt;
                              &lt;tank&gt; 
                                  &lt;temp&gt;&lt;xsl:value-of select="fmp:COL[10]/fmp:DATA"/&gt;&lt;/temp&gt;
                              &lt;/tank&gt;
                          &lt;/date&gt;
                   &lt;!-- &lt;/xsl:for-each&gt; --&gt;
          &lt;/xsl:for-each&gt;
  
      &lt;/fishroom&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p><strong>Input XML:</strong></p>
  
  <pre><code>&lt;row&gt;
      &lt;col&gt;1/1/14&lt;/col&gt;
      &lt;col&gt;tank1&lt;/col&gt;
      &lt;col&gt;data1&lt;/col
  &lt;/row&gt;
  &lt;row&gt;
      &lt;col&gt;1/1/14&lt;/col&gt;
      &lt;col&gt;tank2&lt;/col&gt;
      &lt;col&gt;data3&lt;/col&gt;
  &lt;/row&gt;
  &lt;row&gt;
      &lt;col&gt;1/2/14&lt;/col&gt;
      &lt;col&gt;tank1&lt;/col&gt;
      &lt;col&gt;data2&lt;/col&gt;
  &lt;/row&gt;
  </code></pre>
  
  <p><strong>Desired Output:</strong></p>
  
  <pre><code>&lt;tank1&gt;
      &lt;date&gt;1/1/14
           &lt;somedata&gt;data2&lt;/somedata&gt;
      &lt;/date&gt;
      &lt;date&gt;1/2/14
           &lt;somedata&gt;data1&lt;/somedata&gt;
     &lt;/date&gt;
  &lt;/tank1&gt;
  &lt;tank2&gt;
       &lt;date&gt;1/2/14
           &lt;somedata&gt;data3&lt;/somedata&gt;
        &lt;/date&gt;
  &lt;/tank2&gt;
  </code></pre>