Solved

Xpath - how to get distinct values

Posted on 2009-07-03
2
1,415 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
xpath sql query 2008 8 64
Help with Syntax 9 57
CFML - <CFIF structKeyExists(node, "field")> is returning "NO" consistently and incorrectly? 3 36
xml with php question 5 52
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Suggested Courses

739 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