Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
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 November 5th, 2007, 05:44 AM
Authorized User
Join Date: Nov 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default List of Distinct values using xpath and javascript

   How to do the unique grouped values which stored as attribute in the tag using xpath....?

Here is my xml data;

    <s:Schema id='RowsetSchema'>
    <z:row Region='Asia' City='Coimbatore' Category='AAA' Amt='90'/>
    <z:row Region='Asia' City='Coimbatore' Category='BBB' Amt='91'/>
    <z:row Region='Asia' City='Singapore' Category='AAA' Amt='92'/>
    <z:row Region='Asia' City='Chennai' Category='BBB' Amt='93'/>

Here Im using the xpath in javascript in .Net 2.0 also in VBA;
xmlNode = xml.selectNodes("//z:row[not(@Category=preceding-sibling::*/@Category)]/@Category");

Seems to be very slow when having huge data. I have tried using "distinct-values", but it's throwing error "Unknown method".

Here I want to get the output as like AAA,BBB,CCC... using xpath in javascript and also for VBA using MSXML2.

Pls help me out to solve this problem...

Thanks in advance:)

Old November 5th, 2007, 05:58 AM
samjudson's Avatar
Friend of Wrox
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts

Well this would be very slow, because for the nth node it will have to check every attribute of the preceding n-1 nodes.

The reason distinct-values doesn't work is that its a XSLT 2.0 function, and neither Microsoft processor supports XSLT 2.0.

I can't think of a better way of doing this in one line of XPath - sorting the nodes by Category and just looking at the previous node would be quicker I suspect, but that's not as easy as it sounds, due to the preceding-ssibling axis always being original document order.

/- Sam Judson : Wrox Technical Editor -/
Old November 5th, 2007, 06:11 AM
Authorized User
Join Date: Nov 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts

 yes, I know..., but i want the alternate solution(xpath and its functions which supports in .Net 2.0 @client side javascript also for VBA MSXML2)


Old November 5th, 2007, 06:24 AM
mhkay's Avatar
Wrox Author
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

Like Sam, I can't really offer any easy answer, given that you're stuck with XPath 1.0. The best answer might be to iterate over the sibling elements from Javascript, adding each value to a set of values maintained at the Javascript level.

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Old November 5th, 2007, 06:52 AM
Authorized User
Join Date: Nov 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts

Thx Sam and MhKay!

   Can u help me to write an XSL to iterate instead of using javascript and I'll transform using javascript.

Pls help me!

Thank you!


Similar Threads
Thread Thread Starter Forum Replies Last Post
getting distinct values from attribute markus2000 XSLT 1 June 13th, 2006 03:06 AM
count distinct values Chris Cash XSLT 3 June 8th, 2006 04:55 PM
distinct-values in Javascript Jan1 XML 2 October 10th, 2005 04:56 AM
Distinct values of data arnabghosh Access 18 September 13th, 2005 05:41 PM
DISTINCT ntext Values fleming SQL Server 2000 2 July 23rd, 2005 06:58 PM

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