2013-11-28 50 views
1

p.xml查找XQuery與主根相同節點值

<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> 

我的代碼是

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 

我需要約翰Cieslewicz肯內特·A·羅斯在結果但只顯示Kenneth A. Ross

回答

1

如果要列出誰出現多次的作者,你需要在全球範圍內指望他們在所有作者的列表,而不是在本地訴訟的作者列表:非常

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 
+0

@BeniBala謝謝! – Sandy