title: Sort groups by arregate element property in xslt
body: <p>I'm transforming some xml using xslt (version 1.0, using MSXSL).</p>
  
  <p>Say my xml data looks like this:</p>
  
  <pre><code>&lt;table&gt;
   &lt;record&gt;&lt;name&gt;A&lt;/name&gt;&lt;value&gt;a&lt;/value&gt;&lt;size&gt;10&lt;/size&gt;&lt;/record&gt;
   &lt;record&gt;&lt;name&gt;A&lt;/name&gt;&lt;value&gt;b&lt;/value&gt;&lt;size&gt;35&lt;/size&gt;&lt;/record&gt;
   &lt;record&gt;&lt;name&gt;A&lt;/name&gt;&lt;value&gt;c&lt;/value&gt;&lt;size&gt;60&lt;/size&gt;&lt;/record&gt;
   &lt;record&gt;&lt;name&gt;B&lt;/name&gt;&lt;value&gt;x&lt;/value&gt;&lt;size&gt;15&lt;/size&gt;&lt;/record&gt;
   &lt;record&gt;&lt;name&gt;B&lt;/name&gt;&lt;value&gt;y&lt;/value&gt;&lt;size&gt;90&lt;/size&gt;&lt;/record&gt;
   &lt;record&gt;&lt;name&gt;B&lt;/name&gt;&lt;value&gt;z&lt;/value&gt;&lt;size&gt;20&lt;/size&gt;&lt;/record&gt;
   ...
  &lt;/table&gt;
  </code></pre>
  
  <p>My goal is:</p>
  
  <ol>
  <li>to group the records by <code>&lt;name&gt;</code></li>
  <li>per group, determine the maximum <code>&lt;size&gt;</code>, say <code>maxsize</code></li>
  <li>sort the groups by their <code>maxsize</code> (descending)</li>
  <li>per group, list the records (in original order)</li>
  </ol>
  
  <p>So the result could be:</p>
  
  <pre><code>&lt;table&gt;
   &lt;group&gt;B&lt;maxsize&gt;90&lt;/maxsize&gt;
    &lt;record&gt;&lt;value&gt;x&lt;/value&gt;&lt;size&gt;15&lt;/size&gt;
    &lt;record&gt;&lt;value&gt;y&lt;/value&gt;&lt;size&gt;90&lt;/size&gt;
    &lt;record&gt;&lt;value&gt;z&lt;/value&gt;&lt;size&gt;20&lt;/size&gt;
   &lt;/group&gt;
   &lt;group&gt;A&lt;maxsize&gt;60&lt;/maxsize&gt;
    &lt;record&gt;&lt;value&gt;a&lt;/value&gt;&lt;size&gt;10&lt;/size&gt;
    &lt;record&gt;&lt;value&gt;a&lt;/value&gt;&lt;size&gt;35&lt;/size&gt;
    &lt;record&gt;&lt;value&gt;a&lt;/value&gt;&lt;size&gt;60&lt;/size&gt;
   &lt;/group&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Now steps 1, 2 and 4, I can do that. But... how can I order the groups by their maximum size?</p>
  
  <p>I tried building a new node set in a variable, containing the groups. I can build such a set but I can only access it as a string.</p>
  
  <p>Should be possible, right?</p>