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) { ...@@ -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):) (: let $store := xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple-presort.xml", $tei):)
(: return $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 $fully-sorted := presort:sort-integrations($tei)
let $store := xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple-presort.xml", $fully-sorted) let $store := xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple-presort.xml", $fully-sorted)
return $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()* { declare function presort:sort($nodes as node()*) as node()* {
for $node in $nodes for $node in $nodes
return return
...@@ -81,7 +117,10 @@ declare function presort:sort($nodes as node()*) as node()* { ...@@ -81,7 +117,10 @@ declare function presort:sort($nodes as node()*) as node()* {
presort:default-return($node) presort:default-return($node)
default return default return
presort:default-return($node) if($node/@type = "interlinear") then
()
else
presort:default-return($node)
}; };
declare function presort:keep-node($node as node()*) as node()* { declare function presort:keep-node($node as node()*) as node()* {
...@@ -94,23 +133,33 @@ declare function presort:keep-node($node as node()*) as node()* { ...@@ -94,23 +133,33 @@ declare function presort:keep-node($node as node()*) as node()* {
declare function presort:apply-all-nexts($node as node()*) { declare function presort:apply-all-nexts($node as node()*) {
(: entry point :) if($node[self::tei:addSpan]) then
if($node/@next and not($node/@prev)) then let $spanTo := substring-after($node/@spanTo, "#")
let $next-node := presort:find-corresp-node($node, "next") let $anchor := $node/following::tei:anchor[@xml:id = $spanTo]
let $nodes-inbetween := $node/following-sibling::*[. << $anchor]
return return
(presort:keep-node($node), for $node-inbetween in $nodes-inbetween return
(: (functx:remove-attributes($node, "next"),:) presort:keep-node($node-inbetween)
presort:apply-all-nexts($next-node))
(: exit point :)
else if(not($node/@next)) then
(: functx:remove-attributes($node, "prev"):)
presort:keep-node($node)
else else
let $next-node := presort:find-corresp-node($node, "next") (: entry point :)
return if($node/@next and not($node/@prev)) then
(: (functx:remove-attributes($node, ("next", "prev")),:) let $next-node := presort:find-corresp-node($node, "next")
(presort:keep-node($node), return
presort:apply-all-nexts($next-node)) (presort:keep-node($node),
(: (functx:remove-attributes($node, "next"),:)
presort:apply-all-nexts($next-node))
(: exit point :)
else if(not($node/@next)) then
(: 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")),:)
(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