Solved

Xpath - how to get distinct values

Posted on 2009-07-03
2
1,413 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
API Soap Calls 4 117
Insert Powershell variable into XML 4 48
Create html table using xsl 8 36
split XML field into many fields from MS Access 21 28
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…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

831 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