Created
April 21, 2016 16:28
-
-
Save wsalesky/3f6d75b7c933e69b1e375f66f70efc30 to your computer and use it in GitHub Desktop.
Create new TEI bibl records from bhse-reconciled-authors.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.0"; | |
(: | |
: Create new TEI bibl records from bhse-reconciled-authors.xml | |
: Save records to db, must be logged into eXist as admin/with admin privileges | |
:) | |
declare default element namespace "http://www.tei-c.org/ns/1.0"; | |
declare namespace tei = "http://www.tei-c.org/ns/1.0"; | |
declare namespace syriaca = "http://syriaca.org"; | |
declare namespace functx = "http://www.functx.com"; | |
declare function syriaca:make-persName($input-node as node()*,$old-non-bhse-bibls as node()*,$new-bibl-prefix as xs:string*) | |
as element()* | |
{ | |
for $node in $input-node | |
let $bibl-position := index-of($old-non-bhse-bibls/@xml:id,replace($node/@source,'#','')) | |
let $source := if(matches($node/@source,'#bib[\d]+-1$')) then | |
concat('#',$new-bibl-prefix,1) | |
else concat('#',$new-bibl-prefix,$bibl-position+1) | |
return | |
element {xs:QName('persName')} { | |
$node/@*[name()!='source'], | |
attribute {xs:QName('source')} {$source}, | |
$node/node()} | |
}; | |
declare function syriaca:persName-id($input-node as node()*,$person-id as xs:string*) | |
as element()* | |
{ | |
for $node at $i in $input-node | |
let $id := concat('name',$person-id,'-',$i) | |
return | |
element {xs:QName('persName')} { | |
$node/@*, | |
attribute {xs:QName('xml:id')} {$id}, | |
$node/node()} | |
}; | |
let $bhse-authors-doc := 'bhse-authors.xml' | |
let $bhse-authors := $bhse-authors-doc//person | |
(:For each person:) | |
for $person at $i in $bhse-authors/(author|editor)[@xml:id] | |
(: If author/editor has @xml:id:) | |
(: Grab @xml:id:) | |
let $temp-id := $person/@xml:id | |
(: Assign person URI:) | |
let $person-id := 2783 + $i | |
let $work-id := replace(replace($person/@source, '#bib',''),'-1$','') | |
(: Create Zanetti bibl:) | |
let $bhs-idno := doc(concat('/db/apps/srophe-data/data/works/tei/',$work-id,'.xml'))//idno[@type='BHS'] | |
let $bhse-bibl := | |
<bibl xml:id='{concat('bib',$person-id,'-1')}'> | |
<title level="m" xml:lang="la">Bibliotheca Hagiographica Syriaca</title> | |
<ptr target="http://syriaca.org/bibl/649"/> | |
<citedRange unit="entry">{$bhs-idno}</citedRange> | |
</bibl> | |
(: Replace bibl IDs:) | |
let $old-bibl-prefix := concat('bib',$temp-id,'-') | |
let $new-bibl-prefix := concat('bib',$person-id,'-') | |
let $old-non-bhse-bibls := $person/../bibl[starts-with(@xml:id,$old-bibl-prefix)] | |
let $new-non-bhse-bibls := | |
for $bibl at $i in $old-non-bhse-bibls | |
let $new-bibl-id := concat($new-bibl-prefix,1+$i) | |
let $new-bibl := <bibl xml:id='{$new-bibl-id}'>{$bibl/node()}</bibl> | |
return $new-bibl | |
let $persName-lang-order := ('syr','en','ar') | |
let $persNames := | |
( | |
for $lang in $persName-lang-order | |
return syriaca:make-persName($person/persName[starts-with(@xml:lang,$lang) and contains(@syriaca-tags,'#syriaca-headword')],$old-non-bhse-bibls,$new-bibl-prefix), | |
syriaca:make-persName($person/persName[not(starts-with(@xml:lang,$persName-lang-order)) and contains(@syriaca-tags,'#syriaca-headword')],$old-non-bhse-bibls,$new-bibl-prefix), | |
for $lang in $persName-lang-order | |
return syriaca:make-persName($person/persName[starts-with(@xml:lang,$lang) and not(contains(@syriaca-tags,'#syriaca-headword'))],$old-non-bhse-bibls,$new-bibl-prefix), | |
syriaca:make-persName($person/persName[not(starts-with(@xml:lang,$persName-lang-order)) and not(contains(@syriaca-tags,'#syriaca-headword'))],$old-non-bhse-bibls,$new-bibl-prefix) | |
) | |
(: Assign persName @xml:ids:) | |
let $persNames-w-id := syriaca:persName-id($persNames, $person-id) | |
let $other-nodes := $person/*[not(name()=('persName','bibl'))] | |
let $en-title := string($persNames-w-id[starts-with(@xml:lang,'en') and contains(@syriaca-tags,'#syriaca-headword')][1]) | |
let $syr-headword := string($persNames-w-id[starts-with(@xml:lang,'syr') and contains(@syriaca-tags,'#syriaca-headword')][1]) | |
let $syr-headword-foreign := <foreign xml:lang='syr'>{$syr-headword}</foreign> | |
let $syr-title := | |
if ($syr-headword) then | |
(' — ',$syr-headword-foreign) | |
else () | |
let $record-title := ($en-title,$syr-title) | |
return | |
for $pers in $persNames | |
return string-join($pers[starts-with(@xml:lang,'en') and contains(@syriaca-tags,'#syriaca-headword')]/child::*,' ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment