title: Group same attributes on xslt
body: <p>I have a XML file as following and I want to Group the books based on the published year and    count the number of books for each year. sort the result by ascending order.</p>
  
  <pre><code>&lt;body&gt;
    &lt;outline text="A"&gt;
      &lt;outline text="Abelson, Harold" author="Harold Abelson" title="Struktur und Interpretation von Computerprogrammen. Eine Informatik-Einführung" publisher="Springer Verlag" isbn="3540520430" year="1991"/&gt;
      &lt;outline text="Abrahams, Paul W." author="Paul W. Abrahams" title="Tex for the Impatient" publisher="Addison-Wesley Pub Co" isbn="0201513757" year="2000"/&gt;
    &lt;/outline&gt;
    &lt;outline text="B"&gt;
      &lt;outline text="Bach, Fred" author="Fred Bach" title="UNIX Handbuch zur Programmentwicklung" publisher="Hanser Fachbuchverlag" isbn="3446151036"/&gt;
      &lt;outline text="Bach, Maurice J." author="Maurice J. Bach" title="Design of the UNIX Operating System" publisher="Prentice Hall PTR" isbn="0132017997" year="1986"/&gt;
    &lt;/outline&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Here is the excepted output
  
      </p>
  
  <pre><code>    &lt;p&gt; Group by Year &lt;/p&gt;
      &lt;table border="1"&gt;
          &lt;tr bgcolor="yellow"&gt;
              &lt;th&gt;Year&lt;/th&gt;
              &lt;th&gt;Number&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;1963&lt;/td&gt;
              &lt;td&gt;1&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;1966&lt;/td&gt;
              &lt;td&gt;1&lt;/td&gt;
          &lt;/tr&gt;
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;xsl:template match="body"&gt;
      &lt;xsl:copy&gt;
        &lt;table border="1"&gt;     
          &lt;tr bgcolor="Yellow"&gt;
              &lt;th class="cell"&gt;&lt;span&gt; Year &lt;/span&gt;&lt;/th&gt;
              &lt;th class="cell"&gt;&lt;span&gt; Count &lt;/span&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;xsl:apply-templates select="outline"/&gt;
        &lt;/table&gt;
      &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
  
   &lt;xsl:key  name="groupbyyear"  match="outline" use="@year"/)/&gt;
     &lt;xsl:template match="outline/outline"&gt;
      &lt;tr&gt;
        &lt;xsl:sort select="year" order="ascending" /&gt;
      &lt;/tr&gt;
    &lt;/xsl:template&gt;
  
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>I'm not sure how to use the xsl key function and what should I do inside the template after the key function?</p>