Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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

 

Reply With Quote
  #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/

Reply With Quote
  #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

Reply With Quote
  #4 (permalink)  
Old June 8th, 2006, 04:55 PM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:56 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.