how to return only distinct values from xpath expression

Hi Experts,

This might be a quick one but I am struggling to figure out how to do it.
I have the following xpath expression:
doc("E://xml.xml") /*/diving[./sites[3] and vessel="Compass"]/date

This xpath returns the dates where more than 3 sites have been operated on by the Compass vessel.
<?xml version="1.0" encoding="UTF-8"?>
<date>13-09-2015</date>
<date>19-09-2015</date>
<date>27-09-2015</date>
<date>27-09-2015</date>
<date>27-09-2015</date>


As you can see, the 27-09-2015 appears three times!
How can I rewrite my xpath expression for it to return only distinct values (i.e. no repeats)

Thanks,
Smanyx
SmanyxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
Hi, you could write an XPath expression that does this for you.
But I saw on one of your earlier questions that you were using the XPath in the context of an XSLT
XSLT has some extra functionality that makes this request easier such as key()
Can you confirm that essentialy you need this inside an XSLT?
0
Geert BormansInformation ArchitectCommented:
oh, and a demo xml would help
0
Geert BormansInformation ArchitectCommented:
diving[./sites[3] and vessel="Compass"][not(date = preceding-sibling::diving[./sites[3] and vessel="Compass"]/date)]/date

could work, provided the structure of your source XML

if not

diving[./sites[3] and vessel="Compass"][not(date = preceding::diving[./sites[3] and vessel="Compass"]/date)]/date
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

SmanyxAuthor Commented:
Both expressions yield the expected result.
Thanks.

P.S. Could you recommend some very well written documentation on xpath, xslt and xquery? I know there heaps of stuff on the Internet but what I want is something that takes you into the learning journey quite comprehensively and with a lot of examples, practical exercises...
0
Geert BormansInformation ArchitectCommented:
For me by far the best learning resource for XSLT and XPath is Doug Tidwells book
http://shop.oreilly.com/product/9780596527211.do
2nd edition is more complete and does XSLT2
if you are only into XSLT1, the first edition is a splendid journey and easy read.

I use that book for XSLT trainings for a while now, and I could not have a better background resource for my students. I think it fits your requirement well.
There are ebooks from it and you can find them online for free (so you can evaluate, please buy if you are happy)

Once you get the grips
http://www.wrox.com/WileyCDA/WroxTitle/XSLT-2-0-and-XPath-2-0-Programmer-s-Reference-4th-Edition.productCd-0470192747.html
is a must have reference book on your desk

Patricia Walmsleys book on XQuery is a good resource (after you get the grip on Xpath)
I only have the first edition, I think it is worth buying the second that got update for XQuery 3.1
http://www.amazon.com/XQuery-Search-Across-Variety-Data/dp/1491915102/ref=dp_ob_image_bk
1
SmanyxAuthor Commented:
Thank you so much !!
0
Geert BormansInformation ArchitectCommented:
welcome
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.