XQuery : Filter out duplicates [modified]
-
I have an XML file which stores information of authors and books written by them. The following XQuery returns me a list of authors:- { for $b in doc("http://www.bn.com/bib.xml")//author return } However the resultset returned is:- - (since there could be more than 1 book written by an author) How do I change the above query to filter out duplicates? I saw a few sites which suggested using 'intersect'.I also came across the distinct-values function But I do not know how to use it in this example. Pls suggest:~ -- modified at 7:47 Thursday 13th July, 2006
-
I have an XML file which stores information of authors and books written by them. The following XQuery returns me a list of authors:- { for $b in doc("http://www.bn.com/bib.xml")//author return } However the resultset returned is:- - (since there could be more than 1 book written by an author) How do I change the above query to filter out duplicates? I saw a few sites which suggested using 'intersect'.I also came across the distinct-values function But I do not know how to use it in this example. Pls suggest:~ -- modified at 7:47 Thursday 13th July, 2006
Got it with "distinct-values" :) { let $a := doc("http://www.bn.com/bib.xml")//author for $last in distinct-values($a/last), $first in distinct-values($a[last=$last]/first) return {$last}{$first} }