Subject: Re: How to sort a nodeset returned by key()?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 8 Apr 2008 23:12:17 +0100
|
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="xml" indent="yes" encoding="UTF-8"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
omit-xml-declaration="yes" />
<xsl:strip-space elements="*"/>
<xsl:key name="accounts-by-region" match="/demo/salesman/account"
use="@region"/>
<xsl:template match="/demo">
<html>
<head><title>Accounts ordered by region</title></head>
<body>
<table border="1" valign="top">
<tr><th>Region</th><th>Account</th></tr>
<xsl:for-each select="salesman/account[count(. | key('accounts-by-region',@region)[1]) = 1]">
<xsl:sort select="@region"/>
<xsl:for-each select="key('accounts-by-region',@region)">
<xsl:sort select="."/>
<tr>
<xsl:if test="position()=1">
<td rowspan="{last()}">
<xsl:value-of select="@region"/>
</td>
</xsl:if>
<td><xsl:value-of select="."/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
David
| Current Thread |
Olivier Mengué - 8 Apr 2008 21:48:01 -0000
- David Carlisle - 8 Apr 2008 22:13:39 -0000 <=
|
|