Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 1st, 2008, 01:08 PM
Friend of Wrox
Points: 470, Level: 7
Points: 470, Level: 7 Points: 470, Level: 7 Points: 470, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Plano, TX, USA.
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default List of node values, only once for multiples

OK, Subject is odd, but I didn't know how to be descriptive of my problem in the allocated space.

First, I'm using Saxon8B.

What I want to do is create an index of values for a specific node type.

So I have an XML document that has many <ItemName> nodes. Almost all of them have repeated values. I may have 20 with the value of 'Car', 30 with a value of 'Radio', 10 with a value of 'Pencil'.. you get the idea.

I want to create a result set that has each of these names, but only once. Basically a list of unique items. So:

Car
Radio
Pencil

not

Car
Car
Car
..
Car
Radio
Radio
..
Radio
Pencil
Pencil
..
Pencil


Any Ideas?

------------------------
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
 
Old February 1st, 2008, 01:11 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You'll want to use the XPATH 2.0 function distinct-values(), e.g. <xsl:sequence select="distinct-values(ItemName)">

/- Sam Judson : Wrox Technical Editor -/
 
Old February 1st, 2008, 01:14 PM
Friend of Wrox
Points: 470, Level: 7
Points: 470, Level: 7 Points: 470, Level: 7 Points: 470, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Plano, TX, USA.
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

That's what I was looking for..
Thanks!



------------------------
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
 
Old February 1st, 2008, 01:17 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you just want the values, use the distinct-values() function.

If you want to process the groups of elements that share a value in common, use xsl:for-each-group.

Both these features are new in XSLT 2.0.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 1st, 2008, 03:09 PM
Friend of Wrox
Points: 470, Level: 7
Points: 470, Level: 7 Points: 470, Level: 7 Points: 470, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Plano, TX, USA.
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

I was just about to look into xsl:for-each-group when Sam suggested distinct-values().
For now, I just want the list of values, so the function is working fine.

Thanks for all the help!

------------------------
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare




Similar Threads
Thread Thread Starter Forum Replies Last Post
Aggreagation of leaf node values in BSM 2005 chary SharePoint Development 0 September 19th, 2007 06:43 AM
find multiples stealthdevil Access VBA 4 March 6th, 2007 11:26 AM
Access the values from other node pravind XSLT 1 March 6th, 2006 07:42 AM
Accessing values from the last sibling node graywoodhouse XSLT 3 October 29th, 2004 06:15 AM
Avoid duplicate node values nambati XSLT 1 September 8th, 2004 02:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.