Reputation: 13
I have tried all kinds of variations to remove a node from my Input that is a duplicate.
The current expression I am using is as follows:
<Signers>{
let $signers := fn:distinct-values($temp.load/*/Signers)
for $signer in $signers
return
<Signer>{
$signer
}</Signer>
}</Signers>
I have even used $signer/id, $signer/name, etc. but that does not generate the desired output.
Input
<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>
Current Output
<Signers>
<Signer>[email protected] Rogers</Signer>
<Signer>[email protected] White</Signer>
</Signers>
Desired Output
<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>
This has to be simple and I know I am overlooking something. Thank you!
Upvotes: 1
Views: 564
Reputation: 89285
You can do as follows to select by distinct id
:
<Signers>
{
/*/Signers[not(id=preceding-sibling::Signers/id)]
}
</Signers>
Or using distinct-values()
as you attempted to do :
<Signers>
{
let $ids := fn:distinct-values(/*/Signers/id)
for $id in $ids
return
/*/Signers[id=$id][1]
}
</Signers>
Upvotes: 2