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/5852438 to your computer and use it in GitHub Desktop.

Select an option

Save caschwartz/5852438 to your computer and use it in GitHub Desktop.
XQuery - Query to find TEI documents lacking introductions and insert correct introductions based on year of lecture
xquery version "1.0-ml";
(: 4/18/13 Query to find TEI documents lacking introductions and insert correct introductions based on year of lecture :)
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 $noIntroDates := for $teiDoc in $teiDocs
let $front := $teiDoc/tei:TEI/tei:text/tei:front
let $date := $teiDoc/tei:TEI/tei:teiHeader/localtei:metadata/dc:date
where fn:not($front)
return $date
let $withIntroDates := for $teiDoc in $teiDocs
let $front := $teiDoc/tei:TEI/tei:text/tei:front
let $date := $teiDoc/tei:TEI/tei:teiHeader/localtei:metadata/dc:date
where $front
return $date
for $noIntroDate in $noIntroDates
for $withIntroDate in $withIntroDates
let $front := $withIntroDate/following::tei:front
let $body := $noIntroDate/following::tei:body
where $noIntroDate = $withIntroDate
return xdmp:node-insert-before($body, $front)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment