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

RE: question with using Muenchian/xsl:key (Re: sort/group/co

Subject: RE: question with using Muenchian/xsl:key (Re: sort/group/count probl em)
From: Xiaocun Xu <XXu@xxxxxxxxxxxxxxxxxx>
Date: Sat, 11 Nov 2000 19:48:38 -0500
xsl key group
Thanks for the suggestion, Mike.  Yeah, it is indeed clear as mud :)
I kind of understood the find node-set intersection method: if the current
node is part of the same parent, then count(.|$set2)=count($set2).

Since my goal is to find the sum of @units for all items with the same
@itemid under the same itemlist parent, I tried:
sum(item[count(.|key('items-by-itemid',@itemid)[count(.|$this_lists_
items)=count($this_lists_items)][1])=1]/@units)
which returned me "0".

Is this the right way to find the sum of the node-set intersect?

I also tried the normal (inefficient) way of using two XPath:
<xsl:for-each select="item[not(@itemid = preceding-sibling::item/@itemid)]">
  <td class="text" width="48%"><xsl:value-of select="@itemid"/></td>
  <td class="text-right" width="6%"><xsl:value-of select="sum(item[@itemid =
current()/@itemid]/@units)"/></td>
</xsl:for-each>

That also returned me a sum of 0, is there something wrong with my
calculation of sum?

Much thanks,
Xiaocun


-----Original Message-----
From: Mike Brown
To: xsl-list@xxxxxxxxxxxxxxxx
Sent: 11/11/00 3:05 PM
Subject: Re: question with using Muenchian/xsl:key (Re: sort/group/count
probl em)

Xu, Xiaocun wrote:
>   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.

This is *exactly* my problem with xsl:key. The only way to restrict your
key lookup to a certain node-set is to find the intersection of that
node-set and the result of a key lookup across the whole current node's
document.

The "Kaysian Method" of finding node-set intersections is:

	$set1[count(.|$set2)=count($set2)]

With your data, the indicated section will be $set1:
  <xsl:for-each select="item[count(. | key('items-by-itemid',
@itemid)[1]) =1]">
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
And you'll need to prepare a variable for $set2 right before that:
  <xsl:variable name="this_lists_items" select="item"/>

So the for-each should look like (and I haven't tested this):
  <xsl:for-each
select="item[count(.|key('items-by-itemid',@itemid)[count(.|$this_lists_
items)=count($this_lists_items)][1])=1]">

Clear as mud, eh?

   - Mike
____________________________________________________________________
Mike J. Brown, software engineer at         My XML/XSL resources:
webb.net in Denver, Colorado, USA           http://www.skew.org/xml/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 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.