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 June 8th, 2006, 05:31 AM
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default count distinct values

Hi,
I am very new to XSL and am in desperate need of some help
Part of what I need to do is to get a COUNT DISTINCT on my XML file. (I have attached a chunk of the XML below). I know that this could be done in the stored procedure that is querying the tables but that is a really complicated query and I dont want to fiddle with it.

I want a new variable created in my XSLT which will return the count distinct of the different CGPC variations of the CSCI (SCE_DPTC, computer science) records. For example in this XML file i would like the return count to be 3 as there are 3 seperate and distinct SCE_CGPC's.

This is a chunk of the XML file

<z:row SCE_DPTC='CSCI' DPT_NAME='Computer Science (Physical Sciences School)' SCE_CGPC='PGRE' '

 <z:row SCE_DPTC='CSCI' DPT_NAME='Computer Science (Physical Sciences School)' SCE_CGPC='PGRE'

 <z:row SCE_DPTC='CSCI' DPT_NAME='Computer Science (Physical Sciences School)' SCE_CGPC='PGTM'

 <z:row SCE_DPTC='CSCI' DPT_NAME='Computer Science (Physical Sciences School)' SCE_CGPC='PGTM'

 <z:row SCE_DPTC='CSCI' DPT_NAME='Computer Science (Physical Sciences School)' SCE_CGPC='PGTM'

 <z:row SCE_DPTC='CSCI' DPT_NAME='Computer Science (Physical Sciences School)' SCE_CGPC='UGID'

 <z:row SCE_DPTC='CSCI' DPT_NAME='Computer Science (Physical Sciences School)' SCE_CGPC='UGID'


Any help would be greatly appreciated,

Many thanks,
Chris Cash

 

  #2 (permalink)  
Old June 8th, 2006, 06:28 AM
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you are lucky, because
you could do it with the newest "XQuery 1.0 and XPath 2.0 Functions and Operators" spec.

have a look at the function "distinct-values"

at http://www.w3.org/TR/xpath-functions/

  #3 (permalink)  
Old June 8th, 2006, 09:19 AM
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi markus,

Thanks for the reply but I dont think that I have the new Xpath 2.0. Does anyone else know of an alternative method of getting around the problem?

Thanks,
Chris

  #4 (permalink)  
Old June 8th, 2006, 04:55 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 are using XSLT 2.0, use xsl:for-each-group, or the distinct-values() function.

If you are using 1.0, use Muenchian grouping as described at http://www.jenitennison.com/xslt/grouping

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count Distinct Jonas Access 2 August 14th, 2006 01:03 PM
count distinct nodes alexshiell XSLT 2 January 27th, 2005 11:19 AM
sql to return distinct count pbgurl Access VBA 2 October 29th, 2004 06:29 AM
COUNT ON SELECT DISTINCT stmt savoym SQL Language 7 August 28th, 2003 07:58 AM





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