[Home] [By Thread] [By Date] [Recent Entries]
I would also suggest reading the "grouping" pages at Jeni's site (I too spent lot of time on her site, to learn the techniques). But just for fun, I attempted to solve this problem as follows. XSLT 1.0 solution (uses Muenchian grouping technique): <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" /> <xsl:key name="by-color" match="sign" use="color" /> <xsl:template match="signs">
<html>
<head>
<title/>
</head>
<body>
<xsl:for-each select="sign[generate-id() =
generate-id(key('by-color', color)[1])]">
<xsl:sort select="color"/>
<table frame="all" colsep="1" rowsep="1" id="{color}">
<tr>
<th>Name</th>
<th>Shape</th>
</tr>
<xsl:for-each select="key('by-color', color)">
<xsl:sort select="name"/>
<tr>
<td>
<xsl:value-of select="name"/>
</td>
<td>
<xsl:value-of select="shape"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:for-each>
</body>
</html>
</xsl:template></xsl:stylesheet> XSLT 2.0 solution: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="html" /> <xsl:template match="signs">
<html>
<head>
<title/>
</head>
<body>
<xsl:for-each-group select="sign" group-by="color">
<xsl:sort select="current-grouping-key()"/>
<table frame="all" colsep="1" rowsep="1"
id="{current-grouping-key()}">
<tr>
<th>Name</th>
<th>Shape</th>
</tr>
<xsl:for-each select="current-group()">
<xsl:sort select="name"/>
<tr>
<td>
<xsl:value-of select="name"/>
</td>
<td>
<xsl:value-of select="shape"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:for-each-group>
</body>
</html>
</xsl:template></xsl:stylesheet> On 6/5/07, Mark Peters <flickrmeister@xxxxxxxxx> wrote: Hi Everyone, -- Regards, Mukul Gandhi
|

Cart



