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

RE: GROUPING AND KEYS

Subject: RE: GROUPING AND KEYS
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 28 Apr 2009 11:41:57 +0100
RE:  GROUPING AND KEYS
It's worth being clear that we're talking here about the Muenchian method of
grouping in XSLT 1.0. Grouping in XSLT 2.0 is much much simpler. 

> 1 - Is there a way to visualise in XSLT what this key looks like?
> 
> <xsl:key name="partNo" match="partNo" use="@num" />

You can think of it like this: "Each document that contains partNo elements
has an index, allowing a partNo element to be found quickly if the value of
its @num attribute is known". For example, key('partNo', 'P123') returns all
the partNo elements whose @num value is P123.
> 
> 
> In this statement <xsl:for-each 
> select="foo/shift/partNo[count(. | key('partNo', @num)[1]) = 1]">

In XSLT 1.0, there is no simple way of asking "$A is $B", that is, testing
whether two expressions refer to the same node. There are two common
workarounds to this:

generate-id($A) = generate-id($B)

which relies on the fact that if two nodes have the same generated ID then
they are the same node, and

count($A|$B) = 1

which relies on the fact that the union of two singleton sets is a singleton
only if both sets have the same member. In your example, this is the
expression you are seeing.

Specifically, it's selecting every partNo that is the first partNo with a
given @num value. That is "." (the partNo being tested) is the same node as
key('partNo', @num)[1], which is the first partNo with that @num value.
> 
> we are selecting all partNo nodes where count(. | key( 
> 'partNo', @num)[1]) = 1]
> 
> 2 - What does . mean in this expression? the partNo node?

Yes, in a predicate "." refers to the node being tested. 
> 
> 3 - What does | mean? 

It's a union operator, it forms the union of two sets.

Hope this helps.

Michael Kay
http://www.saxonica.com/

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.