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

Re: RE: (Keys on multiple element types)

Subject: Re: RE: (Keys on multiple element types)
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 5 Feb 2002 11:55:16 +0000
element 5 keys
Hi Ahmad,

> You are correct in that I am trying to get to grips with keys, but I
> didnt appreciate that they automatically removed duplicates based on
> certain conditions, i.e if two say <project> nodes were the same.

The keys don't; using the Muenchian method (which uses keys for
efficiency) does. The duplicates are removed by the statement:

  *[generate-id(.) = generate-id(key('rows', name)[1])]

where you select all the elements that are the same element as the
element you get when you use the 'rows' key with that element's name
(i.e. selects the first element with a particular name in the
document). The other elements with that name are still there.

> Jeni's reply would be to use: -
>
> <xsl:key name="rows" match="FILES/*"
>          use="concat(project(), '+', name)" />

I suggested:

<xsl:key name="rows" match="FILES/*"
         use="concat(name(), '+', name)" />

Note that name() is an XPath function that retrieves the name of a
node (in this case the name of the element that you're indexing with
the key) - in your examples it would return things like 'RECORDA',
'RECORDB' or 'RECORDC'. That means that the key values would be things
like 'RECORDA+Fred' or 'RECORDC+Harry'. To get the unique values,
you'd need:

  *[generate-id(.) =
    generate-id(key('rows', concat(name(), '+', name))[1])]

You might find http://www.jenitennison.com/xslt/grouping helpful.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.