Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML 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 May 22nd, 2007, 01:09 AM
Authorized User
 
Join Date: Feb 2006
Location: Seattle, WA, USA.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Grouping and Distinct items

Hello,

Is there a way to get Group items in a node as well as distinct using 1 Xpath expression?


Grouping:
/dataroot/Book[not(Title=preceding-sibling::Book/Title)]/Title");

Distinct:
/dataroot/Book[Title='value']/Title");

Is there a way to combine both of this into 1? I have an XML doc that is sorted and I need to do the above to it.

Thanks!
Reply With Quote
  #2 (permalink)  
Old May 22nd, 2007, 06:08 AM
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

/dataroot/Book/Title[.='value'][1]

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old May 22nd, 2007, 11:06 AM
Authorized User
 
Join Date: Feb 2006
Location: Seattle, WA, USA.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Michael for your help.

I tried your suggestion but I'm having trouble getting it to work:

Code:
titleList = sortedDocument.SelectNodes("/dataroot/Book/Title[Type='" + typeSelected.SelectedValue + "'][1]");
I also tried:
Code:
/dataroot/Book/Title[Type='" + typeSelected.SelectedValue + "'][1]/Title
and
Code:
/dataroot/Book/Title[Type='" + typeSelected.SelectedValue + "']/Title
any thoughts as to why it didn't work?

Reply With Quote
  #4 (permalink)  
Old May 22nd, 2007, 11:29 AM
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

Given that you haven't shown us your source document, it could be any number of things. Perhaps there's a namespace issue.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old May 22nd, 2007, 11:52 AM
Authorized User
 
Join Date: Feb 2006
Location: Seattle, WA, USA.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You are correct Michael... sorry about that.

Here's what the XML structure looks like:

Code:
<?xml version="1.0" encoding="utf-8"?>
<dataroot>
<Book xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <ID>47</ID>
        <Availability>2006-04-18T00:00:00</Availability>
        <Title>
            <Value>Title x</Value>
        </Title>
        <Type>Educational</Type>
    </Book>
  <Book xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <ID>65</ID>
        <Availability>2007-09-26T00:00:00</Availability>
        <Title>
            <Value>Title y</Value>
        </Title>
        <Type>Educational</Type>
    </Book>
  <Book:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <ID>68</ID>
        <Availability>2007-09-26T00:00:00</Availability>
        <Title>
            <Value>Title y</Value>
        </Title>
        <Type>Fiction</Type>
    </Book>
.
.
.
</dataroot>

Reply With Quote
  #6 (permalink)  
Old May 23rd, 2007, 01:11 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

So you need to declare the prefix-uri ,mappings. How you do that depends on which parser you are using. Look at the relevant documentation for "namespace mappings" or similar. If it's MSXML for example search on "SelectionNamespaces", with .NET it's NamespaceManager.

--

Joe (Microsoft MVP - XML)
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
ERROR 145: ORDER BY ITEMS... SELECT DISTINCT... tbaquero SQL Server 2000 7 May 8th, 2008 02:30 AM
Protect cells and allow grouping/un-grouping sfreuden Excel VBA 4 December 14th, 2006 08:01 AM
Get distinct values on *second* grouping of nodes. MissHenesy XSLT 4 October 23rd, 2006 10:34 AM
Distinct SELECT DISTINCT question... EndEffect Classic ASP Databases 4 August 18th, 2005 08:53 AM
xslt 1.0 distinct grouping cassebn XSLT 3 July 30th, 2003 07:31 AM



All times are GMT -4. The time now is 04:06 AM.


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