XML中的重复数据

时间:2011-03-22 21:44:24

标签: xml xquery

如何获取在变量中不重复的()数据。

我使用这个功能:

.
.
.
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)
};
.
.
.

这是XML示例,我只想获取Joseph的信息,但我只得到重复的数据

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

从评论中更新

  

我想得到的数据不是   重复;如果你看到XML示例,   这是我想得到的结果:

<hospital>
    <person>
        <idee>1902</idee>
        <name>Joseph</name>
        <age>60</age>
        <room>4</room>
        <service>false</service>
    </person>
</hospital>

1 个答案:

答案 0 :(得分:1)

两个XQuery表达式:

/hospital/person[not(name = (../person except .)/name)]

/hospital/person[not(index-of(../person/name,name)[2])]