topical media & game development
professional-xml-08-language-foreachgroup.xsl / xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" exclude-result-prefixes="xs fn xdt">
<xsl:output method="xhtml" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" version="1.0" indent="yes" encoding="UTF-16"/>
<xsl:template match="/">
<html>
<body>
<table>
<tbody>
<tr>
<th>Country</th>
<th>Company</th>
</tr>
<xsl:for-each-group select="customers/customer" group-by="address/country">
<xsl:sort select="address/country" data-type="text"/>
<tr>
<td colspan="2" bgcolor="#E0E0E0">
<xsl:value-of select="address/country"/>
</td>
</tr>
<xsl:for-each select="current-group()">
<xsl:sort select="company" data-type="text" />
<tr>
<td> </td>
<td>
<xsl:value-of select="company"/>
</td>
</tr>
</xsl:for-each>
</xsl:for-each-group>
</tbody>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.