2017-04-25 123 views
1

我嘗試了各種各樣的變化,從我的輸入中刪除一個節點是重複的。XQuery 1.0刪除重複的節點值

我使用的電流表達式如下:

<Signers>{ 
      let $signers := fn:distinct-values($temp.load/*/Signers) 
      for $signer in $signers 
    return 
    <Signer>{ 
     $signer 
    }</Signer> 
}</Signers> 

我甚至已經使用$簽名/ ID,$簽名/名稱等,但不產生所需的輸出。

輸入

 <Signers> 
      <id>a1546000000xtaqAAA</id> 
      <email>[email protected]</email> 
      <name>Jack Rogers</name> 
     </Signers> 
     <Signers> 
      <id>a1546000000xwNSAAY</id> 
      <email>[email protected]</email> 
      <name>Walter White</name> 
     </Signers> 
     <Signers> 
      <id>a1546000000xwNSAAY</id> 
      <email>[email protected]</email> 
      <name>Walter White</name> 
     </Signers> 

電流輸出

<Signers> 
     <Signer>[email protected] Rogers</Signer> 
     <Signer>[email protected]mail.comWalter White</Signer> 
    </Signers> 

所需的輸出

  <Signers> 
      <id>a1546000000xtaqAAA</id> 
      <email>[email protected]</email> 
      <name>Jack Rogers</name> 
     </Signers> 
     <Signers> 
      <id>a1546000000xwNSAAY</id> 
      <email>[email protected]</email> 
      <name>Walter White</name> 
     </Signers> 

這必須是簡單的,我知道我忽視的東西。謝謝!

回答

1

你可以做如下的不同id選擇:

<Signers> 
{ 
    /*/Signers[not(id=preceding-sibling::Signers/id)] 
} 
</Signers> 

demo

或者使用distinct-values()你試圖做:

<Signers> 
{ 
    let $ids := fn:distinct-values(/*/Signers/id) 
    for $id in $ids 
    return 
     /*/Signers[id=$id][1] 
} 
</Signers>