Developed XQuery to add image linking to despatches
Posted by mholmes on 14 Aug 2008 in Activity log
Worked out and tested a method for using XUpdate to add an explicit <biblScope> tag to the header of documents for which we have image scans. The code is below. I borrowed (and slightly modified) a function from FunctX for padding strings. This has been successfully run on a test collection comprising all the 1858 documents. I'll do a backup of the whole database, and run it on the whole collection when I'm confident (or perhaps just integrate the updated files from the test collection).
declare default element namespace "http://www.tei-c.org/ns/1.0";
declare namespace functx = "http://www.functx.com";
declare function functx:pad-string-to-length
( $stringToPad as xs:string? ,
$padChar as xs:string ,
$length as xs:integer) as xs:string {
let $currLen := string-length($stringToPad),
$totalNewChars := ($length - $currLen),
$pad := if ($totalNewChars gt 0) then string-join(for $i in (1 to $totalNewChars) return $padChar, '') else ''
return concat($pad, $stringToPad)
} ;
for $t in collection('/db/coldesp/test/')//TEI[starts-with(./teiHeader/fileDesc/sourceDesc/bibl/date/@when, '1858')]
let $b := $t/teiHeader/fileDesc/sourceDesc/bibl,
$d := $t/teiHeader/fileDesc/sourceDesc/bibl/date,
$fname := concat('co_', $b/idno[@type='coNumber'], '_', functx:pad-string-to-length($b/idno[@type='coVol'], '0', 2), '_', functx:pad-string-to-length($b/idno[@type='page'], '0', 5), 'r.jpg'),
$bs := <biblScope type="startPageImage" facs="{concat('co_', $b/idno[@type='coNumber'], '_', functx:pad-string-to-length($b/idno[@type='coVol'], '0', 2), '/', $fname)}">{$fname}</biblScope>
where not($t/teiHeader/fileDesc/sourceDesc/bibl/biblScope[@type='startPageImage'])
return
if (collection('/db/coldesp/scans/')//graphic[@url=$fname]) then
<done>{update insert $bs preceding $d}</done>
else concat('Not used: ', $fname)