[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

What is wrong with this key element?

Subject: What is wrong with this key element?
From: "Yang" <sfyang@xxxxxxxxxxxxx>
Date: Thu, 6 Sep 2001 17:46:14 +0800
unicat name
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.