[xsl] Categorise Node by Unique Attribute

Subject: [xsl] Categorise Node by Unique Attribute
From: William Warby <untrusted@xxxxxxxxxxxx>
Date: Thu, 08 Jan 2009 12:05:15 +0000
Hi all.

I want to group nodes in an XML file, placing a heading above each category. The category is defined in an attribute which may be the same for a series of records. The code sample below shows what I want to do. I've been going round in circles trying combinations of variables, templates, for-each loops and I just can't seem to get a handle on the problem. Any help would be very gratefully received.

XML Source:

<authors>
  <author name="Steven King">
       <book genre="Drama" name="Book 1" />
       <book genre="Drama" name="Book 2" />
       <book genre="Drama" name="Book 3" />
       <book genre="Sci-Fi" name="Book 4" />
       <book genre="Sci-Fi" name="Book 5" />
   </author>
  <author name="Bill Bryson">
       <book genre="Travel" name="Book 1" />
       <book genre="Travel" name="Book 2" />
       <book genre="History" name="Book 3" />
   </author>
</authors>

Desired output:

<h2>Steven King</h2>
<h3>Drama</h3>
<ul>
   <li>Book 1</li>
   <li>Book 2</li>
   <li>Book 3</li>
</ul>
<h3>Sci-Fi</h3>
<ul>
   <li>Book 4</li>
   <li>Book 5</li>
</ul>
<h2>Bill Bryson</h2>
<h3>Travel</h3>
<ul>
   <li>Book 1</li>
   <li>Book 2</li>
</ul>
<h3>History</h3>
<ul>
   <li>Book 3</li>
</ul>


I am using classic ASP, MSXML2.DOMDocument.6.0


Current Thread