[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] What is wrong with this key element?
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|