Commit 4f786357 authored by mrodzis's avatar mrodzis 🌎
Browse files

Improve sorting of interlinear additions (cf. print#35)

parent ddff6cb6
......@@ -24,12 +24,48 @@ declare function presort:main($tei as node()*) as element(tei:text) {
(: let $store := xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple-presort.xml", $tei):)
(: return $tei:)
let $tei := presort:sort($tei)
let $prepared := presort:prepare($tei)
let $tei := presort:sort($prepared)
let $fully-sorted := presort:sort-integrations($tei)
let $store := xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple-presort.xml", $fully-sorted)
return $fully-sorted
};
declare function presort:prepare($nodes as node()*) as node()* {
for $node in $nodes
return
typeswitch ($node)
case text() return
$node
case comment() return
()
default return
let $addSpan := $node/preceding-sibling::*[self::tei:addSpan][1][@place = 'interlinear'][@prev or @next]
return
if($addSpan and not($node[self::tei:anchor])) then
let $spanTo := substring-after($addSpan/@spanTo, "#")
let $anchor := $addSpan/following::tei:anchor[@xml:id = $spanTo]
let $nodes-inbetween := $addSpan/following-sibling::*[. << $anchor]
return
element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
$node/@*,
if(functx:is-node-in-sequence-deep-equal($node, $nodes-inbetween)) then
attribute type {"interlinear"}
else
(),
$node/node()
}
else
element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
$node/@*,
presort:prepare($node/node())
}
};
declare function presort:sort($nodes as node()*) as node()* {
for $node in $nodes
return
......@@ -81,6 +117,9 @@ declare function presort:sort($nodes as node()*) as node()* {
presort:default-return($node)
default return
if($node/@type = "interlinear") then
()
else
presort:default-return($node)
};
......@@ -94,21 +133,31 @@ declare function presort:keep-node($node as node()*) as node()* {
declare function presort:apply-all-nexts($node as node()*) {
if($node[self::tei:addSpan]) then
let $spanTo := substring-after($node/@spanTo, "#")
let $anchor := $node/following::tei:anchor[@xml:id = $spanTo]
let $nodes-inbetween := $node/following-sibling::*[. << $anchor]
return
for $node-inbetween in $nodes-inbetween return
presort:keep-node($node-inbetween)
else
(: entry point :)
if($node/@next and not($node/@prev)) then
let $next-node := presort:find-corresp-node($node, "next")
return
(presort:keep-node($node),
(: (functx:remove-attributes($node, "next"),:)
(: (functx:remove-attributes($node, "next"),:)
presort:apply-all-nexts($next-node))
(: exit point :)
else if(not($node/@next)) then
(: functx:remove-attributes($node, "prev"):)
(: functx:remove-attributes($node, "prev"):)
presort:keep-node($node)
else
let $next-node := presort:find-corresp-node($node, "next")
return
(: (functx:remove-attributes($node, ("next", "prev")),:)
(: (functx:remove-attributes($node, ("next", "prev")),:)
(presort:keep-node($node),
presort:apply-all-nexts($next-node))
};
......
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