Commit 34864110 authored by mrodzis's avatar mrodzis 🌿
Browse files

Simplify white space setting, remove dead code

parent cfb5a856
......@@ -34,12 +34,8 @@ declare function tidySimple:main($tei as node()*, $uri as xs:string) {
let $tidy := tidySimple:enhance-handshifts($tei//tei:text)
=> tidySimple:sort-out-surplus-elements()
=> tidySimple:sort-out-invalid-hands()
=> tidySimple:whitespaces()
=> tidySimple:split-headings()
=> tidySimple:remove-surplus-lines()
=> tidySimple:summarize()
(: => tidySimple:sort():)
(: let $text-with-sections := tidySimple:make-structure($clear-surplus-hands):)
let $header :=
tidySimple:get-Fontanes-sources($tei//tei:teiHeader[parent::tei:TEI])
=> tidySimple:get-references-in-abstract()
......@@ -148,24 +144,6 @@ as node()* {
tidySimple:sort-out-surplus-elements($node/node())
}
else if($node/@unit = "line") then
let $next-pb := $node/following::tei:pb[1]
let $nodes-on-page := $node/preceding::tei:pb[1]/following::node()[. << $next-pb][functx:node-kind(.) = "text"]
let $contains-text :=
for $node-pb in $nodes-on-page return
if(normalize-space($node-pb) != "") then
true()
else
false()
return
if(functx:is-value-in-sequence(true(), $contains-text)) then
element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
$node/@*,
tidySimple:sort-out-surplus-elements($node/node())
}
else
()
else
element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
$node/@*,
......@@ -216,9 +194,7 @@ declare function tidySimple:copy-element($node as node(), $flag as xs:string)
{
element {QName("http://www.tei-c.org/ns/1.0", $node/name())}{
$node/@*,
if($flag = "structure") then
tidySimple:make-structure($node/node())
else if($flag = "post") then
if($flag = "post") then
tidySimple:sort-out-invalid-hands($node/node())
else if($flag = "surplus") then
tidySimple:sort-out-invalid-hands($node/node())
......@@ -226,14 +202,12 @@ declare function tidySimple:copy-element($node as node(), $flag as xs:string)
tidySimple:enhance-handshifts($node/node())
else if($flag = "sources") then
tidySimple:get-Fontanes-sources($node/node())
else if($flag = "lines") then
tidySimple:remove-surplus-lines($node/node())
else if($flag = "summarize") then
tidySimple:summarize($node/node())
else if($flag = "ref") then
tidySimple:get-references-in-abstract($node/node())
else
tidySimple:tidy($node/node())
text{"!!!Kopieren des Elements fehlgeschlagen!!!"}
}
};
......@@ -311,135 +285,6 @@ declare function tidySimple:enhance-medium($node as node(), $medium as xs:string
$medium
};
(:~
:
: :)
declare function tidySimple:make-structure($nodes as node()*) as node()* {
for $node in $nodes return
typeswitch ($node)
case text() return
if(tidySimple:is-in-section($node)) then
()
else
$node
case element(tei:milestone) return
if($node/@unit = "section") then
tidySimple:make-section($node)
else if($node/@unit = "paragraph") then
tidySimple:copy-element($node, "structure")
(: lines in sections have to be ignored since they are copied into
the section with get-section-chunk :)
else if($node/@unit = "line"
and tidySimple:is-in-section($node)) then
()
else
tidySimple:copy-element($node, "structure")
case element(tei:anchor) return
if (matches($node/preceding::tei:milestone/@spanTo, $node/@xml:id)) then
()
else
tidySimple:copy-element($node, "structure")
default return
if(tidySimple:is-in-section($node)) then
()
else
tidySimple:copy-element($node, "structure")
};
(:~
: Checks if a given node is between a tei:milestone[@unit = "section"] and its
: corresponing tei:anchor.
:
: @author Michelle Weidling
: @param the current node
: @return xs:boolean
: :)
declare function tidySimple:is-in-section($node as node()) as xs:boolean {
let $prev-section-marker := $node/preceding::tei:milestone[1][@spanTo]
let $target-id := replace($prev-section-marker, "#", "")
let $next-anchor := $node/following::tei:anchor[matches(@xml:id, $target-id)]
return
if($prev-section-marker
and $next-anchor) then
true()
else
false()
};
(:~
: Creates a tei:div from a given tei:milestone[@unit = "section"] that contains
: all elements from a given tei:milestone to its corresponding tei:anchor.
:
: Since the nodes between the current and the target one may also contain
: structural information (e.g. tei:milestone[@unit = "paragraph"]), these nodes
: cannot simply be copied but have to be transformed as well.
:
: @author Michelle Weidling
: @param $node the current tei:milestone[@unit = "section"]
: @return element(tei:div)
: :)
declare function tidySimple:make-section($node as element(tei:milestone))
as element(tei:div) {
element tei:div {
attribute type {"section"},
tidySimple:get-section-chunk($node)
}
};
(:~
: Returns all nodes between a tei:milestone[@unit = "section"] and its
: corresponding tei:anchor.
:
: @author Michelle Weidling
: @param the current tei:milestone element
: @return all nodes between the current element and the respective tei:anchor
:)
declare function tidySimple:get-section-chunk($node as element(tei:milestone))
as node()* {
let $target-id := substring-after($node/@spanTo, "#")
let $target := $node/following::tei:anchor[matches(@xml:id, $target-id)]
return
$node/following-sibling::node()[. << $target]
};
declare function tidySimple:tidy($nodes as node()*) as node()* {
()
};
declare function tidySimple:whitespaces($nodes as node()*) as node()* {
for $node in $nodes return
typeswitch($node)
case text() return
$node
default return
element {QName("http://www.tei-c.org/ns/1.0", $node/name())} {
$node/@*,
if($node/@next) then
let $target-id := replace($node/@next, "#", "")
let $target := $node/ancestor::tei:TEI//*[@xml:id = $target-id]
return
if(ends-with($node//text()[last()], "@P")
(: example: C6 Kapell:drf. :)
or $node[self::tei:abbr][ends-with(., ":")]
or $node[self::tei:rs]/tei:choice[not(following-sibling::*)][tei:abbr[ends-with(., ":")]]
or $node[ends-with(., "-")]) then
()
else
attribute break {"true"}
else
(),
tidySimple:whitespaces($node/node())
}
};
declare function tidySimple:split-headings($nodes as node()*) as node()* {
......@@ -548,34 +393,6 @@ declare function tidySimple:get-Fontanes-sources($header as node()*) {
};
declare function tidySimple:remove-surplus-lines($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 = 'line']
and $node/preceding-sibling::*[1][self::tei:rs[@next]]) then
let $target-id := replace($node/preceding-sibling::*[1][self::tei:rs]/@next, "#", "")
return
if($node/following-sibling::node()[1][self::tei:rs][@xml:id = $target-id]) then
()
else
tidySimple:copy-element($node, "lines")
else
tidySimple:copy-element($node, "lines")
default return
tidySimple:copy-element($node, "lines")
};
declare function tidySimple:summarize($nodes as node()*) as node()* {
for $node in $nodes return
......@@ -627,26 +444,27 @@ declare function tidySimple:apply-all-nexts($node as node()) as node()* {
(: entry point of virtual aggregation:)
if($node/@next and not($node/@prev)) then
let $next-node := tidySimple:find-corresp-node($node, "next")
let $nodes-inbetween := $node/following::node()[. << $next-node]
return
if(count($next-node) = 1) then
(tidySimple:summarize($node/node()),
$nodes-inbetween,
tidySimple:apply-all-nexts($next-node))
else
()
(: last of a virtual aggregation: exit point :)
else if(not($node/@next)) then
($node/preceding::tei:milestone[@unit = "handshift"][1],
tidySimple:summarize($node/node()))
tidySimple:summarize($node/node())
(: element in the middle of a virtual aggregation:)
else
let $next-node := tidySimple:find-corresp-node($node, "next")
let $prev-handshift := $node/preceding::tei:milestone[@unit = "handshift"][1]
let $nodes-inbetween := $node/following::node()[. << $next-node]
return
if(count($next-node) = 1) then
($prev-handshift,
tidySimple:summarize($node/node()),
(tidySimple:summarize($node/node()),
$nodes-inbetween,
tidySimple:apply-all-nexts($next-node))
else
()
......
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