[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
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|