?
Solved

Xpath - how to get distinct values

Posted on 2009-07-03
2
Medium Priority
?
1,417 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 2000 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 Create Failover DNS Record Sets in Route 53

Route 53 has the ability to easily configure DNS record sets specifically for failover scenarios. These failover record sets can be configured to failover to full-blown deployments in other regions or to a static HTML page that informs your customers of the issue.

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

765 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