2

我有一个 XML 数据库,其中包含具有 id 的元素。这些都是独一无二的。它们还有一个辅助标识符,将它们链接到另一个数据库中的类似对象。这些并非都是独一无二的。

是否有可以让我识别所有非唯一 ID 的 XQuery?我可以计算有多少使用 distinct-values(),但这无助于识别有重复的 ID!

XML 示例:(每个对象都包含在 eXist 数据库中的单独文件中)

<object id="uniqueID123">
  <secondary identifier="nonUnique888"/>
</object>

<object id="uniqueID456">
  <secondary identifier="nonUnique888"/>
</object>

<object id="uniqueID789">
  <secondary identifier="Unique999"/>
</object>

我想识别重复的字符串“nonUnique888”。

4

3 回答 3

3

以下查询返回所有非唯一标识符:

let $sec := doc('source')/root/object/secondary
for $id in distinct-values($sec/@identifier)
where count($sec[@identifier eq $id]) gt 1
return $id
于 2010-10-06T18:49:05.220 回答
2

使用

let $vSeq := /object/secondary/@identifier
  return
    $vSeq[index-of($vSeq,.)[2]] 

阅读这里的解释。

于 2010-10-07T18:49:17.130 回答
0

在 xml 文件中使用此代码存储

let $path:="/db/test/all.xml"
let $a := xmldb:store( $col,'adub.xml',<root></root>)  

let $sec := doc($path)//profile
for $id in distinct-values($sec/mail)
where count($sec[mail eq $id]) gt 1
return 
 update insert  
            <profile>
                {$id}
                </profile>
   into  doc($a)/root 
于 2016-05-10T09:55:57.043 回答