Commit 98ab2ddd authored by mrodzis's avatar mrodzis 🐸
Browse files

Feature/#95 macro sorting

parent 38815146
...@@ -21,6 +21,7 @@ import module namespace config="http://textgrid.de/ns/SADE/config" at "../../con ...@@ -21,6 +21,7 @@ import module namespace config="http://textgrid.de/ns/SADE/config" at "../../con
import module namespace fontaneSimple="http://fontane-nb.dariah.eu/teisimple" at "tei2teisimple.xqm"; import module namespace fontaneSimple="http://fontane-nb.dariah.eu/teisimple" at "tei2teisimple.xqm";
import module namespace fsort="http://fontane-nb.dariah.eu/sort" at "sort.xqm"; import module namespace fsort="http://fontane-nb.dariah.eu/sort" at "sort.xqm";
import module namespace functx = "http://www.functx.com"; import module namespace functx = "http://www.functx.com";
import module namespace macro-sort="http://fontane-nb.dariah.eu/macro-sort" at "macro-sort.xqm";
import module namespace prepCom="http://fontane-nb.dariah.eu/prepCom" at "prepcom.xqm"; import module namespace prepCom="http://fontane-nb.dariah.eu/prepCom" at "prepcom.xqm";
import module namespace presort="http://fontane-nb.dariah.eu/presort" at "presort.xqm"; import module namespace presort="http://fontane-nb.dariah.eu/presort" at "presort.xqm";
import module namespace simple2xhtml="http://fontane-nb.dariah.eu/simple2xhtml" at "simple2xhtml.xqm"; import module namespace simple2xhtml="http://fontane-nb.dariah.eu/simple2xhtml" at "simple2xhtml.xqm";
...@@ -156,11 +157,13 @@ declare function etTransfo:create-htmls($showcase as xs:string) as xs:string+ { ...@@ -156,11 +157,13 @@ declare function etTransfo:create-htmls($showcase as xs:string) as xs:string+ {
: @param $tei The current notebook as element(tei:TEI) : @param $tei The current notebook as element(tei:TEI)
:) :)
declare function etTransfo:transform-tei($tei as element(tei:TEI)) { declare function etTransfo:transform-tei($tei as element(tei:TEI)) {
(: macro-sort:main($tei, $tei/@id):)
(: => fsort:main():)
fsort:main($tei) fsort:main($tei)
=> prepCom:main($tei/@id) => prepCom:main($tei/@id)
=> fontaneSimple:main($tei/@id) => fontaneSimple:main($tei/@id)
=> tidySimple:main($tei/@id) => tidySimple:main($tei/@id)
(: => simple2xhtml:main($tei/@id):) => simple2xhtml:main($tei/@id)
}; };
...@@ -201,13 +204,7 @@ declare function etTransfo:create-print-tei() as xs:string { ...@@ -201,13 +204,7 @@ declare function etTransfo:create-print-tei() as xs:string {
declare function etTransfo:get-all-xmls() as node()+ { declare function etTransfo:get-all-xmls() as node()+ {
for $res in collection($config:data-root || "/print/xml/") for $res in collection($config:data-root || "/print/xml/")
[contains(base-uri(.), ".xml") [contains(base-uri(.), ".xml")
and not(contains(base-uri(.), "tmp")) and not(contains(substring-after(base-uri(.), "/print/xml/"), "-"))]
and not(contains(base-uri(.), "presort"))
and not(contains(base-uri(.), "prepared"))
and not(contains(base-uri(.), "prepcom"))
and not(contains(base-uri(.), "fontane"))
and not(contains(base-uri(.), "all-headers"))
and not(contains(base-uri(.), "Kasten"))]
order by $res/tei:TEI/@key1, number($res/tei:TEI/@key2) order by $res/tei:TEI/@key1, number($res/tei:TEI/@key2)
return return
$res $res
......
xquery version "3.1";
module namespace macro-sort="http://fontane-nb.dariah.eu/macro-sort";
import module namespace config="http://textgrid.de/ns/SADE/config" at "../../config/config.xqm";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace xi="http://www.w3.org/2001/XInclude";
declare function macro-sort:main($tei as node()*, $uri as xs:string) as node()* {
let $header := $tei//tei:teiHeader
let $sorted := macro-sort:sort($tei//tei:sourceDoc)
(: let $cleared := macro-sort:clear($sorted):)
let $cleared := $sorted
let $final-tei :=
element tei:TEI {
$header,
$cleared
}
let $store := xmldb:store($config:data-root || "/print/xml/", $uri || "-macrosort.xml", $final-tei)
return
$final-tei
};
declare function macro-sort:sort($nodes as node()*) as node()* {
for $node in $nodes return
typeswitch ($node)
case text() return
$node
case comment() return
$node
case element(tei:milestone) return
if($node/@unit = "section") then
let $end-point-id := replace($node/@spanTo, "#", "")
let $end-point := $node/root()//tei:anchor[@xml:id = $end-point-id]
let $number := substring-after($node/@type, "Text_")
let $handshift := $node/preceding::tei:milestone[@unit = "handshift"][1]
return
element tei:div {
attribute n {$number},
(: $node/(@* except @spanTo),:)
$node/@*,
$handshift,
(: all nodes on the current surface :)
$node/following-sibling::node()[. << $end-point],
$node/../following-sibling::node()[. << $end-point],
(: all complete surfaces before the anchor :)
$node/ancestor::tei:surface/following-sibling::tei:surface[. << $end-point],
(: all elements on the surface that contains the anchor which are before the anchor :)
$node/ancestor::tei:surface/following-sibling::tei:surface[descendant::tei:anchor[@xml:id = $end-point-id]]//tei:anchor[@xml:id = $end-point-id]/preceding-sibling::*
}
else
macro-sort:copy-element($node)
default return
let $section-marker := $node/preceding::tei:milestone[@unit = "section"][1]
let $end-point-id := replace($section-marker/@spanTo, "#", "")
let $end-point := $node/root()//tei:anchor[@xml:id = $end-point-id]
return
if($node[. >> $section-marker and . << $end-point]) then
()
else
macro-sort:copy-element($node)
};
declare function macro-sort:copy-element($node as element(*)) as element(*) {
element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
$node/@*,
macro-sort:sort($node/node())
}
};
declare function macro-sort:clear($nodes as node()*) as node()* {
for $node in $nodes return
typeswitch ($node)
case text() return
$node
case comment() return
$node
default return
if($node/@outside-section = "true") then
()
else
$node
};
...@@ -132,7 +132,7 @@ as xs:boolean { ...@@ -132,7 +132,7 @@ as xs:boolean {
declare function prepCom:get-editorial-note($node as element(*)) declare function prepCom:get-editorial-note($node as element(*))
as element(tei:note)? { as element(tei:note)? {
$node/ancestor::tei:TEI//tei:note[contains(@target, $node/@xml:id)] $node/root()//tei:note[@type = "editorial"][@target = "#" || $node/@xml:id]
}; };
......
Supports Markdown
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