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
  #1 (permalink)  
Old November 13th, 2008, 06:39 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 How to determine if an element value is unique?

Brain freeze time again..

Running Saxon 9

I have a structure with a bunch of elements scattered throughout the tree.

I need to validate that each instance of this particular element has a unique text value.

Is this a for-each-group type problem?

------------------------
Keep Moving Forward

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
  #2 (permalink)  
Old November 13th, 2008, 07:38 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

The simplest is

count($values) = count(distinct-values($values))

In practice you may be interested then to find out where the duplicates are, which you can do using for-each-group

<xsl:for-each-group select="$values" group-by=".">
  <xsl:if test="count(current-group()) gt 1">
     ...

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
  #3 (permalink)  
Old November 17th, 2008, 12:12 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

Thanks, the second example is what I was thinking about.
Works like a champ

------------------------
Keep Moving Forward

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

Michael Hare


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem adding element to the previous element dani1 XSLT 5 September 10th, 2008 01:38 AM
translate element name to element name lexzeus XSLT 3 September 4th, 2006 09:04 AM
Determine Credentials bmumph C# 2 November 1st, 2005 12:18 PM
adding of element and assigning to one element sushovandatta XSLT 2 November 16th, 2004 07:04 PM
Need Help: Can't determine cause of error xgbnow Visual C++ 3 September 22nd, 2003 05:00 PM





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