Repeated data in a XML

匆匆过客 提交于 2019-12-20 07:42:31

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!