title: Performing a "Group By" query in XPath XSL
body: <p>Given the following XML:</p>
  
  <pre><code>&lt;results name="queryResults"&gt;
    &lt;int name="intfield1:[* TO 10]"&gt;11&lt;/int&gt; 
    &lt;int name="intfield2:[10 TO 20]"&gt;9&lt;/int&gt; 
    &lt;int name="intfield1:[10 TO 20]"&gt;12&lt;/int&gt; 
  &lt;/results&gt;
  </code></pre>
  
  <p>I would like to produce this XML:</p>
  
  <pre><code>&lt;results&gt;
      &lt;field name="numberfield1"&gt;
          &lt;value name="[* TO 10]"&gt;11&lt;/value&gt;
          &lt;value name="[10 TO 10]"&gt;12&lt;/value&gt;
      &lt;/field&gt;
      &lt;field name="numberfield2"&gt;
          &lt;value name="[10 TO 20]"&gt;9&lt;/value&gt;
      &lt;/field&gt;
  &lt;/results&gt;
  </code></pre>
  
  <p>I can't think how to do this in XSL mainly because i'm wanting to Group by the numbericfield.. All i can come up with is this:</p>
  
  <pre><code>&lt;xsl:if test="count(results/int) &amp;gt; 0"&gt;
      &lt;results&gt;
      &lt;xsl:for-each select="results/int"&gt;
          &lt;field&gt;
              &lt;xsl:attribute name="name"&gt;
                  &lt;xsl:value-of select="substring-before(@name, ':')"/&gt;&lt;/xsl:attribute&gt;
              &lt;value&gt;
                  &lt;xsl:attribute name="name"&gt;
                      &lt;xsl:value-of select="substring-after(@name, ':') "/&gt;
                  &lt;/xsl:attribute&gt;
                  &lt;xsl:value-of select="."/&gt;
              &lt;/value&gt;
          &lt;/field&gt;
      &lt;/xsl:for-each&gt;
      &lt;/results&gt;
  &lt;/xsl:if&gt;
  </code></pre>
  
  <p>However this doesn't produce the nice grouped list instead i get this:</p>
  
  <pre><code>&lt;results&gt;
      &lt;field name="numberfield1"&gt;
          &lt;value name="[* TO 10]"&gt;11&lt;/value&gt;
      &lt;/field&gt;
      &lt;field name="numberfield2"&gt;
          &lt;value name="[10 TO 20]"&gt;9&lt;/value&gt;
      &lt;/field&gt;
      &lt;field name="numberfield1"&gt;
          &lt;value name="[10 TO 10]"&gt;12&lt;/value&gt;
      &lt;/field&gt;
  &lt;/results&gt;
  </code></pre>
  
  <p>If someone can stear me in the right direction.. That would be great?</p>
  
  <p>Thanks</p>