问题
How can I get the () data which it's not repeated in a variable.
I use this function:
.
.
.
let $person:= $hopital1/persona
for $seq in (1 to count($derechohabiente))
return
$person[$seq]
[not(xf:is-node-secuence-equal(.,$person[position() < $seq])) ]
declare function xf:is-node-secuence-equal ( $node as node()? , $seq as node()*) as xs:boolean {
some $nodeInSeq in $seq satisfies fn:deep-equal($nodeInSeq/name, $node/ns0:name)
};
.
.
.
This is the XML example, I just want to get Joseph's information, but I get only the data repeated
<?xml version="1.0"?>
<hospital>
<person>
<idee>1902</idee>
<name>Joseph</name>
<age>60</age>
<room>4</room>
<service>false</service>
</person>
<person>
<idee>3246</idee>
<name>John</name>
<age>34</age>
<room>0</room>
<service>false</service>
</person>
<person>
<idee>3246</idee>
<name>John</name>
<age>34</age>
<room>0</room>
<service>true</service>
</person>
<person>
<idee>3246</idee>
<name>John</name>
<age>34</age>
<room>5</room>
<service>true</service>
</person>
</hospital>
Update from comments
I want to get the data which is not repeated; if you see the XML example, this is the result I'd like to get:
<hospital> <person> <idee>1902</idee> <name>Joseph</name> <age>60</age> <room>4</room> <service>false</service> </person> </hospital>
回答1:
Two XQuery expressions:
/hospital/person[not(name = (../person except .)/name)]
And
/hospital/person[not(index-of(../person/name,name)[2])]
来源:https://stackoverflow.com/questions/5398216/repeated-data-in-a-xml