Skip to content

Instantly share code, notes, and snippets.

@wsalesky
Created June 30, 2016 02:14
Show Gist options
  • Select an option

  • Save wsalesky/a60b12eaea9846c50b8a168319947b85 to your computer and use it in GitHub Desktop.

Select an option

Save wsalesky/a60b12eaea9846c50b8a168319947b85 to your computer and use it in GitHub Desktop.
Update persNames in attestations with headwords and @ref
xquery version "3.0";
import module namespace functx="http://www.functx.com";
declare namespace tei = "http://www.tei-c.org/ns/1.0";
declare function local:parse-name($name){
if($name/child::*) then
string-join(for $part in $name/child::*
order by $part/@sort ascending, string-join($part/descendant-or-self::text(),' ') descending
return $part/text(),' ')
else $name/text()
};
for $r in collection('/db/apps/srophe-data/data/persons/tei')//tei:event[@type="attestation"]
let $id := $r/ancestor::tei:person/tei:idno[@type='URI'][starts-with(.,'http://syriaca.org')]
let $original := $r
let $title := $r/descendant::tei:title
let $author :=
<persName ref="{$id}">{local:parse-name($r/ancestor::tei:person/tei:persName[@syriaca-tags='#syriaca-headword'][@xml:lang='en'][1])}</persName>
let $new-content :=
<p xml:lang="en" xmlns="http://www.tei-c.org/ns/1.0">
{($author, ' is commemorated in ', $title,'.')}
</p>
return update replace $r/child::* with $new-content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment