Subject: question with using Muenchian/xsl:key (Re: sort/group/count probl em) From: "Xu, Xiaocun" <XXu@xxxxxxxxxxxxxxxxxx> Date: Sat, 11 Nov 2000 13:47:10 -0500 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: Converting attributes into chil, jlangdon | Thread | Re: question with using Muenchian/x, Mike Brown |
XPath help, Robert Koberg | Date | RE: XPath help, edmund mitchell |
Month |