XML Grouping Problem
I'm trying to transform a XML file I have output from an Oracle database using Oracle's Java SDK.
The output comes in a standard format:
<ROWSET>
<ROW rownum="1">
<COLNAME>Data...</COLNAME>
<COLNAME>Data...</COLNAME>
</ROW>
<ROW rownum="2">
<COLNAME>Data...</COLNAME>
<COLNAME>Data...</COLNAME>
</ROW>
...
</ROWSET>
The problem I have is that I have grouped data, for example:
<ROWSET>
<ROW rownum="1">
<STUDENTID>10002</STUDENTID>
<NAME>Fred</NAME>
<SURNAME>Bloggs</SURNAME>
<COURSE>Geography For Beginners</COURSE>
</ROW>
<ROW rownum="2">
<STUDENTID>10002</STUDENTID>
<NAME>Fred</NAME>
<SURNAME>Bloggs</SURNAME>
<COURSE>Advanced English</COURSE>
</ROW>
<ROW rownum="3">
<STUDENTID>10010</STUDENTID>
<NAME>Arnie</NAME>
<SURNAME>Middle</SURNAME>
<COURSE>Math</COURSE>
</ROW>
<ROW rownum="4">
<STUDENTID>10010</STUDENTID>
<NAME>Arnie</NAME>
<SURNAME>Middle</SURNAME>
<COURSE>Physics</COURSE>
</ROW>
...
</ROWSET>
Obviously, course is at the wrong level. This is a result of the records returned from the
database in a 'flat' format:
10002, "Fred", "Bloggs", "Geography For Beginners"
10002, "Fred", "Bloggs", "Advanced English"
What is the best way to transform this into the following format?:
<ROWSET>
<ROW rownum="1">
<STUDENTID>10002</STUDENTID>
<NAME>Fred</NAME>
<SURNAME>Bloggs</SURNAME>
<COURSES>
<COURSE>Geography For Beginners</COURSE>
<COURSE>Advanced English</COURSE>
<COURSES>
</ROW>
...
</ROWSET>
I've been reading Micheal Kay's XSLT book on pages 622-626, but unfortunately
his example uses data with attributed vales e.g.
<cities>
<city name="Paris" country="France">
<city name="Djon" country="France">
<city name="Crossville" country="US">
</cities>
I'm fairly new to XSLT so I've no idea how I'd translate his example to my situation.
Any ideas on how I would approach my problem? Thanks.
|