Skip to content

Instantly share code, notes, and snippets.

@micheee
Created May 21, 2012 10:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micheee/2761801 to your computer and use it in GitHub Desktop.
Save micheee/2761801 to your computer and use it in GitHub Desktop.
Groups authors by author/name and returns all authors that have more than one distinct author/@id attribute
let $authors :=
<authors>
<author id="a"><name>Foo</name>…whatever…</author>
<author id="b"><name>Foo</name>…whatever…</author>
<author id="a"><name>Foo</name>…whatever…</author>
<author id="c"><name>Bar</name>…whatever…</author>
<author id="d"><name>Bar</name>…whatever…</author>
<author id="f"><name>FooBar</name>…whatever…</author>
</authors>
return
<distinct-names> {
for $author in $authors//author
group by $name := $author/name
return
if(count(distinct-values($author/@id)) > 1) then
element {"author"}
{
attribute {"name"} {$name},
for $id in distinct-values($author/@id)
return <id>{$id}</id>
}
else ()
}</distinct-names>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment