Here is a simplified version of the problem I'm working on: I have a bunch of xml data that encodes information about people. Each person is uniquely identified by the id attribute, but can have many names. For example, in one document I could find
<person id=1>Paul Mcartney</person>
<person id=2>Ringo Starr</person>
And in another I can find:
<person id=1>Sir Paul McCartney</person>
<person id=2>Richard Starkey</person>
I want to use xquery to create a new document that lists all the names associated with this identifier. i.e:.
<person id=1>
<name>Paul McCartney</name>
<name>Sir Paul McCartney</name>
<name>James Paul McCartney</name>
</person>
<person id=2>
...
</person>
The way I'm doing it now in xquery looks like this (pseudocode-esque):
let $ids := distinct-terms( [all the id attributes on people] )
for $id in $ids
return <person id={$id}>
{
for $unique-name in distinct-values
(
for $name in ( [all names] )
where $name/@id=$id
return $name
)
return <name>{$unique-name}</name>
}
</person>
, . , , ( 1200). (300 , 800 xml), 12 , , 1200 4 ( - 3 ). , , . Saxon, java 10 (!), , 6 .
, ( Python pseudocode):
persons = {}
for id in ids:
person[id] = set()
for person in all_the_people_in_my_xml_document:
persons[person.id].add(person.name)
, XML-. , - xquery? , , ( ). , , , Python, xquery ( ) .
- ? , - , xquery, ? , , , .