[xsl] What is wrong with this key element?

Subject: [xsl] What is wrong with this key element?
From: "Yang" <sfyang@xxxxxxxxxxxxx>
Date: Thu, 6 Sep 2001 17:46:14 +0800
Hi,
I need your help on this problem using key element
for categorizing the product code from its first three letters.

**xml ***

<doc>
<z ProdCode="1100300"/>
<z ProdCode="1110040"/>
<z ProdCode="1100400"/>
</doc>

**desired solution **
110
1100300
1100400
111
1110040

**  xsl **
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; >

<xsl:output method="xml" indent="yes"/>
<xsl:key name="prodCat" match="@ProdCode" use="substring(@ProdCode,1,3)"/>

<xsl:variable name="uniCat"
select="//z/@ProdCode[generate-id(.)=generate-id(key('prodCat',substring(@Pr
odCode,1,3))[1])]"/>

<xsl:template match="/">

Category<xsl:value-of select="count($uniCat)"/>
<table width="80%" bgcolor="brown">
<xsl:for-each select="$uniCat">
<xsl:sort select="."/>
<xsl:variable name="cat" select="substring(.,1,3)"/>
<tr><td><xsl:value-of select="$cat"/></td></tr>

<xsl:for-each select="key('prodCat',$cat)">
<xsl:variable name="pid" select="."/>
<tr bgcolor="yellow">
<td>
<xsl:value-of select="$pid"/>
</td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>

There is something wrong with the key element expression,
I just can not figure out how to get good solution.

Need your kind input badly.  Thanks.


Sun-fu Yang
sfyang@xxxxxxxxxxxxx



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread