Created
September 19, 2016 21:04
-
-
Save peterstadler/c2f7d1bafae28d60a6d01a4d7d76d128 to your computer and use it in GitHub Desktop.
This file contains 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.1"; | |
declare namespace tei="http://www.tei-c.org/ns/1.0"; | |
(: location of the old translation spreadsheet – translated via oxGarage to TEI :) | |
declare variable $local:spreadsheet := doc('/db/apps/TEI/tei-de-i18n.xml'); | |
(: location of the TEI ODD customizations :) | |
declare variable $local:customizations := collection('/db/apps/TEI/odd')//tei:schemaSpec; | |
(: location of p5subset.xml:) | |
declare variable $local:p5subset := doc('/db/apps/TEI/p5subset.xml'); | |
(: main function for creating the table rows :) | |
declare function local:specs2rows($specs as element()*) as element(tei:row)* { | |
for $spec in $specs | |
(: construct the identifier for the row, e.g. "teiHeader" or "att.dimensions/scope/range" :) | |
let $ident := string-join(($spec/ancestor::tei:elementSpec/@ident | $spec/ancestor::tei:classSpec/@ident, $spec/ancestor::tei:attDef/@ident, $spec/@ident), '/') | |
(: the module the current $spec is defined in :) | |
let $module := $spec/@module | |
(: list all TEI customizations that make use of this $spec :) | |
let $customizations := $local:customizations[tei:moduleRef[@key=$module][some $i in tokenize(@include, '\s+') satisfies $i = $ident]]/@ident union $local:customizations[tei:moduleRef[@key=$module][not(@include)]][not(tei:elementSpec[@ident = $ident][@mode='delete'])]/@ident | |
(: grab the appropriate row from the old translation spreadsheet :) | |
let $i18n := $local:spreadsheet//tei:row[tei:cell=$ident] | |
(: see what has changed since then … :) | |
let $desc_changed := normalize-space($spec/tei:desc[@xml:lang='en']) != $i18n/tei:cell[2]/normalize-space() | |
let $gloss_changed := normalize-space($spec/tei:gloss[@xml:lang='en']) != $i18n/tei:cell[4]/normalize-space() | |
let $remarks_changed := $spec/tei:remarks[@xml:lang='en']/normalize-space() != $i18n/tei:cell[6] | |
(: return the merged information :) | |
return ( | |
element tei:row { | |
(: name/identifier :) | |
element tei:cell {$ident}, | |
(: desc :) | |
element tei:cell {$spec/tei:desc[@xml:lang='en']/node()}, | |
(: translated desc :) | |
element tei:cell {$i18n/tei:cell[3]/node()}, | |
(: gloss :) | |
element tei:cell {$spec/tei:gloss[@xml:lang='en']/node()}, | |
(: translated gloss :) | |
element tei:cell {$i18n/tei:cell[5]/node()}, | |
(: remarks :) | |
element tei:cell {$spec/tei:remarks[@xml:lang='en']/node()}, | |
(: translated remarks :) | |
element tei:cell {$i18n/tei:cell[7]/node()}, | |
(: add some comments about changes :) | |
element tei:cell { | |
if($i18n) then ( | |
if($desc_changed) then 'desc changed' else (), | |
if($gloss_changed) then ' gloss changed' else (), | |
if($remarks_changed) then ' remarks changed' else () | |
) | |
else 'In altem Spreadsheet nicht vorhanden' | |
}, | |
(: print the list of customizations we've found this $spec:) | |
element tei:cell { | |
string-join($customizations, ' ') | |
} | |
}, | |
(: recursively dive into attDefs and valItems :) | |
local:specs2rows($spec/tei:attList/tei:attDef | $spec/tei:valList/tei:valItem) | |
) | |
}; | |
<TEI xmlns="http://www.tei-c.org/ns/1.0"> | |
<teiHeader> | |
<fileDesc> | |
<titleStmt> | |
<title>i18n spreadsheet for German Translatathon</title> | |
<author>Peter Stadler</author> | |
</titleStmt> | |
<publicationStmt> | |
<p>No publication statement</p> | |
</publicationStmt> | |
<sourceDesc> | |
<p>A TEI file generated from an XQuery script.</p> | |
</sourceDesc> | |
</fileDesc> | |
</teiHeader> | |
<text> | |
<body> | |
<table> | |
<head>Sheet1</head> | |
<row n="1"> | |
<cell>name</cell> | |
<cell>desc</cell> | |
<cell>translation</cell> | |
<cell>gloss</cell> | |
<cell>translation</cell> | |
<cell>remarks</cell> | |
<cell>translation</cell> | |
<cell>comments</cell> | |
<cell>customizations</cell> | |
</row> | |
{ | |
local:specs2rows($local:p5subset//tei:elementSpec | $local:p5subset//tei:classSpec) | |
} | |
</table> | |
</body> | |
</text> | |
</TEI> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment