[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

Subject: question with using Muenchian/xsl:key (Re: sort/group/count problem)
From: "Xu, Xiaocun" <XXu@xxxxxxxxxxxxxxxxxx>
Date: Sat, 11 Nov 2000 13:47:10 -0500
muenchian xsl
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

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.