Solved

Xpath - how to get distinct values

Posted on 2009-07-03
2
1,412 Views
Last Modified: 2013-11-11
Hi,

I'm using PHP to to this:
$xml = simplexml_load_file("WebsitePropertyData.xml");
$results = $xml->xpath("/dataroot/WebsitePropertyData/City");

It returns cities. I want to know how to return distinct values (i.e. no repeats). I am aware of the distinct-values function, but I have no idea how to apply it to my own code.

Thanks,

Warren
0
Comment
Question by:warrenrapson
2 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 24776127
you can only use distinct-values() if you use an XSLT2.0 processor
$results = $xml->xpath("distinct-values(/dataroot/WebsitePropertyData/City)");

likely you will need something like this (which will be slow on huge sets)
$results = $xml->xpath("/dataroot/WebsitePropertyData/City[not(. = preceding::City)]");

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now