Commit 5656f77f authored by mrodzis's avatar mrodzis 🌎
Browse files

Improve sorting (closes print#52)

parent ab1931b7
......@@ -40,6 +40,7 @@ declare function presort:sort($nodes as node()*) as node()* {
()
case element(tei:rs) return
(: for nodes that only have text :)
if($node[@next and not(child::*)]) then
let $next-node := presort:find-corresp-node($node, "next")
return
......@@ -47,6 +48,7 @@ declare function presort:sort($nodes as node()*) as node()* {
($node, $next-node)
else
presort:exclude-copied($node)
(: for nodes that only have text :)
else if($node[@prev and not(child::*)]) then
let $prev-node := presort:find-corresp-node($node, "prev")
return
......@@ -54,24 +56,32 @@ declare function presort:sort($nodes as node()*) as node()* {
()
else
presort:exclude-copied($node)
(: for nodes that only have a tei:hi that is part of a virtual
aggregation. these nodes will be processed in tei:hi :)
else if($node[child::hi[@prev] and count(child::*)= 1]) then
presort:sort($node/node())
else
presort:exclude-copied($node)
default return
if(($node/@next and not($node/@prev))
and not(matches($node/@style, "underline"))) then
presort:apply-all-nexts($node)
else if(($node/@prev or $node/@next)
and not(matches($node/@style, "underline"))) then
let $prev-node := presort:find-corresp-node($node, "prev")
let $next-node := presort:find-corresp-node($node, "next")
case element(tei:hi) return
if($node/@next and not($node/ancestor::tei:rs)) then
let $corresp-node := presort:find-corresp-node($node, "next")
return
if($prev-node or $next-node) then
()
if($corresp-node[self::tei:hi and parent::tei:rs]) then
(presort:keep-node($node),
element {QName("http://www.tei-c.org/ns/1.0", "rs")} {
$corresp-node/parent::*/@*,
$corresp-node
})
else
presort:keep-node($node)
presort:default-return($node)
else
presort:keep-node($node)
presort:default-return($node)
default return
presort:default-return($node)
};
declare function presort:keep-node($node as node()*) as node()* {
......@@ -124,7 +134,7 @@ declare function presort:find-corresp-node($node as node()*, $flag as xs:string)
$node/ancestor::*[last()]//*[@xml:id = $id]
};
declare function presort:exclude-copied($node as node()) as element(tei:rs) {
declare function presort:exclude-copied($node as node()) as element(tei:rs)? {
let $rs-children := $node/node()
let $processed-children :=
for $child in $rs-children return
......@@ -137,8 +147,28 @@ declare function presort:exclude-copied($node as node()) as element(tei:rs) {
$child
return
element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
$node/@*,
$processed-children
}
if(count($processed-children) gt 0) then
element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
$node/@*,
$processed-children
}
else
()
};
declare function presort:default-return($node as node()) as node()* {
if(($node/@next and not($node/@prev))
and not(matches($node/@style, "underline"))) then
presort:apply-all-nexts($node)
else if(($node/@prev or $node/@next)
and not(matches($node/@style, "underline"))) then
let $prev-node := presort:find-corresp-node($node, "prev")
let $next-node := presort:find-corresp-node($node, "next")
return
if($prev-node or $next-node) then
()
else
presort:keep-node($node)
else
presort:keep-node($node)
};
\ No newline at end of file
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