Solved

Xpath - how to get distinct values

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

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 …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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