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

Re: Selecting /getting only one node value out of the

Subject: Re: Selecting /getting only one node value out of the many identical values
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sun, 4 Mar 2001 12:04:57 +0000
preceding node values in xsl
Hi Tapan,

> this XML is genereted based on query from a user and comes from a
> database. I want to display to the user only the available "brands"
> of shirts Ie. output shall be only "Arrow" and "Lee" in my case. and
> the user can then further query on the subitems like "size" and
> "color". SO I want a < Select "brand" from "clothes/category/sno"
> where "there is no repetiion"

Getting the 'distinct' values involves getting only those values that
haven't already occurred in the document.  The basic method of doing
this is to find all the nodes where there isn't a preceding node that
has the same value in the document.

In your case you want all the sno elements:

  clothes/category/sno

And then you want to filter in those where there aren't any preceding
(sibling) sno elements whose brand is the same as the brand of the
particular sno element:

  clothes/category/sno[not(preceding-sibling::sno/brand = brand)]

If you have *lots* of sno elements, then another possibility is to
create a key that indexes the sno elements by brand:

<xsl:key name="sno-by-brand" match="sno" use="brand" />

You can then find all the sno elements with a particular brand (say
'Arrow') with the key() function:

  key('sno-by-brand', 'Arrow')

and you can find all the sno elements that are first in the list of
sno elements of a particular brand, as returned by the key, with:

  clothes/category/sno[generate-id() =
                       generate-id(key('sno-by-brand', brand)[1])]

or:

  clothes/category/sno[count(.|key('sno-by-brand', brand)[1]) = 1]

I hope that helps,

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.