Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
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 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 May 22nd, 2007, 01:09 AM
Authorized User
 
Join Date: Feb 2006
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!
 
Old May 22nd, 2007, 06:08 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old May 22nd, 2007, 11:06 AM
Authorized User
 
Join Date: Feb 2006
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?

 
Old May 22nd, 2007, 11:29 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old May 22nd, 2007, 11:52 AM
Authorized User
 
Join Date: Feb 2006
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>

 
Old May 23rd, 2007, 01:11 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)





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





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