Skip to content

Instantly share code, notes, and snippets.

@caschwartz
Last active December 18, 2015 22:09
Show Gist options
  • Select an option

  • Save caschwartz/5852392 to your computer and use it in GitHub Desktop.

Select an option

Save caschwartz/5852392 to your computer and use it in GitHub Desktop.
XQuery - Query to find TEI documents lacking biographies and insert correct biographies
xquery version "1.0-ml";
(: 4/17/13 Query to find TEI documents lacking biographies and insert correct biographies :)
declare namespace tei = "http://www.tei-c.org/ns/1.0";
declare namespace localtei = "http://digital.library.ptsem.edu/lectures/tei";
declare namespace dc = "http://purl.org/dc/elements/1.1/";
let $teiDocs := fn:collection()
let $noBioAuthors := for $teiDoc in $teiDocs
let $creator := $teiDoc/tei:TEI/tei:teiHeader/localtei:metadata/dc:creator
let $note := $teiDoc/tei:TEI/tei:text/tei:body/tei:note
where fn:not($note[@type = "bio"])
return $creator
let $withBioAuthors := for $teiDoc in $teiDocs
let $creator := $teiDoc/tei:TEI/tei:teiHeader/localtei:metadata/dc:creator
let $note := $teiDoc/tei:TEI/tei:text/tei:body/tei:note
where $note[@type = "bio"]
return $creator
return for $noBioAuthor in $noBioAuthors
for $withBioAuthor in $withBioAuthors
let $bioNote := $withBioAuthor/following::tei:note[@type = "bio"]
let $byline := $noBioAuthor/following::tei:byline
where $noBioAuthor = $withBioAuthor
and $noBioAuthor/following-sibling::dc:date = $withBioAuthor/following-sibling::dc:date
return xdmp:node-insert-after($byline, $bioNote)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment