[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] question with using Muenchian/xsl:key (Re: sort/group/count
Hi, Thanks to Jeni's suggestion, I started to apply Muenchian for grouping. It works well, but I have one problem: since xsl:key is top-level element, I can not seem to apply element scope with it. The XML structure I have is: <itemlist> <item itemid="Z101" units="1"/> <item itemid="Z102" units="2"/> <item itemid="Z101" units="4"/> </itemlist> <itemlist>... What I need is for each itemlist, print out all unique itemids and the sum of their units attribute. The following is what I have in my XSL right now: <xsl:key name="items-by-itemid" match="item" use="@itemid"/> <xsl:template match="itemlist"> <xsl:for-each select="item[count(. | key('items-by-itemid', @itemid)[1]) = 1]"> <xsl:sort select="@itemid" /> <tr> <td><xsl:value-of select="@itemid"/></td> <td><xsl:value-of select="sum(key('items-by-itemid',@itemid)/@units)"/></td> </tr> </xsl:for-each> </xsl:template> key('items-by-itemid', @itemid) returns all items with the same @itemid in the entire XML document. I just want all items with the same @itemid in each of the itemlist element, how can I do that? Much thanks, Xiaocun Xu xxu@xxxxxxxxxxxxxxxxxx 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
|