-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinsert-zotero-id.xql
32 lines (27 loc) · 1.43 KB
/
insert-zotero-id.xql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
xquery version "3.0";
(: NAMESPACES:)
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";
let $works := collection('/db/apps/srophe-data/data/works/tei')/TEI
let $spreadsheet := doc('/db/apps/srophe-data/data/bibl/hagiography-editions-translations.xml')/root
for $bibl in $works//bibl/note[not(@type='MSS')]/bibl[not(ptr) and not(idno)][position() < 10]
let $matching-row := $spreadsheet/row[Author=$bibl/(author|editor) and Title=$bibl/title][1]
let $id-syriaca-matching := $matching-row/Syriaca_ID[1]
let $id-zotero-matching := $matching-row/Zotero_ID[1]
let $idno :=
if ($id-syriaca-matching!='') then
let $URI := concat('http://syriaca.org/bibl/',$id-syriaca-matching/text())
return element ptr {attribute target {$URI}}
else if ($id-zotero-matching!='') then
element idno {attribute type {'zotero'},$id-zotero-matching/text()}
else ()
let $vol := if ($matching-row/Volume_No.[.!='']) then <citedRange unit='vol'>{$matching-row/Volume_No./text()}</citedRange> else ()
let $new-bibl :=
element bibl {$bibl/@*, $bibl/node()[name()!='citedRange'], $idno, $vol, $bibl/citedRange}
return
if ($idno) then
(update insert $new-bibl following $bibl,
update delete $bibl)
else ()