Commit dacc1da6 authored by mrodzis's avatar mrodzis 🦊

Assure dest coll available, small restructuring

parent fceec4d8
......@@ -2,7 +2,10 @@ xquery version "3.1";
(:~
: With this module users can display their TEI documents page-wise. A TEI
: resource is split according to its pagebreaks and the chunks between two
: tei:pb are stored separately in an HTML file.
: tei:pb are stored separately in an HTML file at /db/apps/${YOUR_PROJECT}/templates/${RESOURCE_NAME}/.
:
: To work properly, this module requires all data that has to be transformed to
: be stored at /db/apps/${YOUR_PROJECT}/textgrid/data/.
:
: Limitations and known issues:
: * since SADE uses the TEI stylesheets this functionality tends to be slow for big documents
......@@ -26,13 +29,44 @@ declare variable $pag:stylesheet := doc( substring-before($config:app-root, "/sa
declare function pag:main($uri as xs:string) {
let $doc := doc("/db/apps/sade/textgrid/data/"|| $uri || ".xml")
let $input := pag:paginate($doc/tei:TEI)
let $doc := doc($config:data-root || "/data/"|| $uri || ".xml")
let $input := pag:paginate($doc/tei:TEI, $uri)
return "done"
};
declare function pag:paginate($input as element(tei:TEI), $input-uri as xs:string) {
let $no-of-pages := count($input//tei:pb)
let $dest-coll := "/db/apps/sade/templates/" || $input-uri
let $assure-dir-available :=
if(xmldb:collection-available($dest-coll)) then
()
else
xmldb:create-collection("/db/apps/sade/templates/", $input-uri)
let $filename-prefix := $input-uri
for $i in 1 to $no-of-pages
let $output :=
if ($i < $no-of-pages) then
let $first := $i
let $next := $i + 1
let $output := pag:get-chunk-between($input/descendant::tei:pb[$first], $input/descendant::tei:pb[$next], $input)
return
transform:transform($output, $pag:stylesheet, ())/xhtml:body/node()
else
let $output := pag:get-chunk-between-last($input/descendant::tei:pb[last()], ($input/descendant::tei:pb[1]/following::*[last()]), $input)
return
transform:transform($output, $pag:stylesheet, ())/xhtml:body/node()
return
let $filename-final := $filename-prefix || '_p' || string($i)
let $output := <div>{$output}</div>
let $store := xmldb:store($dest-coll, $filename-final || '.html' , $output )
return $output
};
declare function pag:get-chunk-between(
$ms1 as element(),
$ms2 as element(),
......@@ -42,7 +76,7 @@ declare function pag:get-chunk-between(
typeswitch ($node)
case element() return
if ($node is $ms1) then $node
else if ( some $n in $node/descendant::* satisfies ($n is $ms1 or $n is $ms2) )
else if (some $n in $node/descendant::* satisfies ($n is $ms1 or $n is $ms2))
then
(: element { name($node) } :)
element {QName (namespace-uri($node), name($node))}
......@@ -75,37 +109,11 @@ declare function pag:get-chunk-between-last(
else if ( $node >> $ms1 and $node << $ms2 ) then ($node)
else if ($node is $ms2) then ( $ms2 )
else ()
case attribute() return $node (: will never match attributes outside non-returned elements :)
case attribute() return
$node (: will never match attributes outside non-returned elements :)
default return
if ( $node >> $ms1 and $node << $ms2 ) then $node
else ()
};
declare function pag:paginate($input) {
let $no-of-pages := count($input//tei:pb)
let $dest-coll := "/db/apps/sade/textgrid/" || $input-uri
let $filename-prefix := $input-uri
for $i in 1 to $no-of-pages
let $output :=
if ($i < $no-of-pages) then (
let $first := $i
let $next := $i+1
let $output := pag:get-chunk-between($input/descendant::tei:pb[$first], $input/descendant::tei:pb[$next], $input)
return
transform:transform($output, $pag:stylesheet, ())/xhtml:body/node()
)
else (
let $output := pag:get-chunk-between-last($input/descendant::tei:pb[last()], ($input/descendant::tei:pb[1]/following::*[last()]), $input)
return
transform:transform($output, $pag:stylesheet, ())/xhtml:body/node()
)
return
let $filename-final := $filename-prefix || '_p' || string($i)
let $output := <div>{$output}</div>
let $store := xmldb:store($dest-coll, $filename-final || '.html' , $output )
return $output
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment