Sorting and grouping with XSL Stylesheets

J

Jack Wayne

Hi,
I am using MSXML 3.0rc.

I have a document similar to the following:

<?xml version="1.0"?>
<cars>
<car name="Mercedes">
<model built="1985" style="Sedan">560 SEL</model>
<model built="1979" style="Coupe">520 SLC</model>
</car>
<car name="Dodge">
<model built="2004" style="Wagon">Magnum</model>
<model built="2004" style="Sedan">300</model>
</car>
<car name="Chevrolet">
<model built="2005" style="Sedan">Malibu</model>
<model built="2004" style="Sedan">Malibu</model>
<model built="2003" style="Sedan">Malibu</model>
</car>
<car name="BMW">
<model built="2005" style="Hatchback">Mini</model>
<model built="2005" style="Coupe">315i</model>
<model built="2005" style="Coupe">Z4</model>
</car>
<car name="Cadillac">
<model built="2004" style="SUV">Escalade</model>
<model built="2004" style="Sedan">STS</model>
<model built="2004" style="Sedan">CTS</model>
<model built="1981" style="Coupe">Coupe DeVille</model>
</car>
</cars>

And I would like to produce the following: note that /model of the
same /car@name with the same ( /model/@built and /model/@style ) are
contained in the same <div> and the div are in order of /car/@name,
this needs to be created in an xsl stylesheet, the sorting I can do
but haven't figured out how to group the similar items together.

Any assistance would be most appreciated

Thanks Jack

<div>
<table>
<tr>
<td>BMW - 2005 - Coupe </td>
</tr>
<tr>
<td>315i, Z4</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td>BMW - 2005 - Hatchback</td>
</tr>
<tr>
<td>Mini</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td>Cadillac - 2004 - SUV</td>
</tr>
<tr>
<td>Escalade</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td>Cadillac - 2004 - Sedan</td>
</tr>
<tr>
<td>CTS, STS</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td>Cadillac - 1981 - Coupe</td>
</tr>
<tr>
<td>Copupe DeVille</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td>Chevrolet - 2004 - Sedan</td>
</tr>
<tr>
<td>Malibu</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td>Chevrolet - 2003 - Sedan</td>
</tr>
<tr>
<td>Malibu</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td>Chevrolet - 2002 - Sedan</td>
</tr>
<tr>
<td>Malibu</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td>Dodge - 2004 - Wagon</td>
</tr>
<tr>
<td>Magnum</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td>Dodge - 2004 - Sedan</td>
</tr>
<tr>
<td>300</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td>Mercedes - 1985 - Sedan</td>
</tr>
<tr>
<td>560 SEL</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td>Mercedes - 1979 - Coupe</td>
</tr>
<tr>
<td>520 SLC</td>
</tr>
</table>
</div>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top