Find same node value from main root in xquery

243 views Asked by At

p.xml

<documents>
  <dblp>
    <inproceedings>
      <author>John Cieslewicz</author>
      <author>Kenneth A. Ross</author>
      <author>Kenneth A. Ross</author>
    </inproceedings>
   </dblp>
   <dblp>
    <inproceedings>
      <author>Yi-Reun Kim</author>
      <author>Kyu-Young Whang</author>
      <author>John Cieslewicz</author>
    </inproceedings>
   </dblp>
 <documents>

my code is

for $c in doc("C:\Users\User\Desktop\p.xml")//documents/dblp/inproceedings
where fn:count($c/author) != fn:count(fn:distinct-values($c/author))
return $c/author

I need John Cieslewicz and Kenneth A. Ross in result but its shows only Kenneth A. Ross

1

There are 1 answers

0
BeniBela On BEST ANSWER

If you want to list authors who appear multiple times, you need to count them globally in the list of all authors, not locally in the list of authors of a proceeding:

let $docs := doc("C:\Users\User\Desktop\p.xml")/documents, 
    $authors := $docs//author,
    $distinct-authors := distinct-values($authors)
for $author in $distinct-authors
where count($authors[. eq $author]) > 1 
return $author