Sorting and grouping with XSL Stylesheets

Discussion in 'XML' started by Jack Wayne, Jan 24, 2005.

  1. Jack Wayne

    Jack Wayne Guest

    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>
    Jack Wayne, Jan 24, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Zita

    How to embed xsl-stylesheets in resx-files?

    Andreas Zita, Jan 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    628
    Edwin Knoppert
    Jan 6, 2006
  2. Frank-Ralph Reiser

    Re: XSL: grouping data and group header?

    Frank-Ralph Reiser, Jul 31, 2003, in forum: XML
    Replies:
    0
    Views:
    1,421
    Frank-Ralph Reiser
    Jul 31, 2003
  3. Christian Ludwig

    XSLT: sorting and grouping

    Christian Ludwig, Nov 24, 2003, in forum: XML
    Replies:
    2
    Views:
    602
    Christian Ludwig
    Nov 26, 2003
  4. Sparko
    Replies:
    0
    Views:
    408
    Sparko
    Jul 9, 2004
  5. Replies:
    1
    Views:
    3,595
    A. Bolmarcich
    May 27, 2005
Loading...

Share This Page