I have the following XML document (This example is from W3schools.com with modifications):
<bookstore>
<book>
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<section>Children</section>
<section>Recent</section>
<year>2005</year>
<price>30.00</price>
</book>
<book>
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<section>Children</section>
<section>Recent</section>
<year>2005</year>
<price>29.99</price>
</book>
<book>
<title lang="en">Learning XML 2: The Reckoning</title>
<author>Erik T. Simpson</author>
<section>Terror</section>
<year>2003</year>
<price>9.95</price>
</book>
</bookstore>
How can I retrieve the books which SECTION is the ONLY ONE in the entire document and there is no duplicate? I tried the following XQuery (I need an XQuery for this):
for $x in doc("books.xml")/bookstore/book/
where distinct-values($x/section)
return $x
But it seems returns all of them without duplicates and I want to retrieve the last node, because is the only one with that section.
Any idea? Thank you very much for your support and help!
book
elements with only onesection
child element? What happens if there is abook
with severalsection
child element which are all unique across the document, do you want to select it? Also which version of XQuery do you use? – Martin Honnen