grouping items among a list according to items subtag value

G

Gilles Kuhn

Hello all, here is my problem:
Let's assume I have a movie list containing movies from different
countries. The xml looks like:
<root>
<movie>
<title>matrix</title>
<country>USA</country>
</movie>
<movie>
<title>T3</title>
<country>USA</country>
</movie>
<movie>
<title>tomorrow never dies</title>
<country>GB</country>
</movie>
<movie>
<title>la dolce vita</title>
<country>italy</country>
</movie>
<movie>
<title>la vita e bella</title>
<country>italy</country>
</movie>
</root>

I would like to display a table (in HTML) with:
in the first cell, the movies made in US, in the second, the ones
coming from GB... I assume the list is already sorted. Of course, in
general, I have no idea about the country possible values and the
number of movies.
It should look like that:

<table>
<!-- iteration on the _different_ values of country, which I don't
know a priori -->
<xsl:for-each select="??????????????????????">
<tr>
<td>
<xsl:for-each select="movie[country=XXXXXXXXXXXXXXX]">
<!-- here I put my movie layout -->
<xsl:for-each>
</td>
</tr>
<xsl:for-each>
<table>

Does anyone knows what I should put instead of ??????????????????, and
XXXXXXX?
Or any other method solving the problem (I have tried too, to use
<xsl:if test="not(country=preceding::country)">) to put or not the
<td> and <tr> html tags, but it leads to incorrect tags imbrication
between xsl:if and tr/td...).

Thanks a lot for your help.
 

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,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top