Commit abc13a9a authored by MRodz's avatar MRodz Committed by mrodzis
Browse files

Display only valid tei:handShifts that actually have text

parent 3435c9aa
......@@ -44,7 +44,10 @@ declare
%test:assertEquals("<div xmlns=""http://www.tei-c.org/ns/1.0""><handShift xmlns=""http://www.tei-c.org/ns/1.0"" new=""#Fontane"" script=""Latf""/>Some text<handShift xmlns=""http://www.tei-c.org/ns/1.0"" new=""#Fontane"" script=""Latn""/></div>")
%test:args("<div xmlns=""http://www.tei-c.org/ns/1.0""><handShift xmlns=""http://www.tei-c.org/ns/1.0"" new=""#Fontane"" medium="""" script=""Latn""/>Some text<handShift xmlns=""http://www.tei-c.org/ns/1.0"" new=""#Fontane"" medium="""" script=""Latn""/></div>")
%test:assertEquals("<div xmlns=""http://www.tei-c.org/ns/1.0""><handShift xmlns=""http://www.tei-c.org/ns/1.0"" medium="""" new=""#Fontane"" script=""Latn""/>Some text</div>")
%test:assertEquals("<div xmlns=""http://www.tei-c.org/ns/1.0""><handShift xmlns=""http://www.tei-c.org/ns/1.0"" medium="""" new=""#Fontane"" script=""Latn""/>Some text</div>")
%test:args("<body xmlns=""http://www.tei-c.org/ns/1.0""><milestone xmlns=""http://www.tei-c.org/ns/1.0"" unit=""line""/><handShift xmlns=""http://www.tei-c.org/ns/1.0"" new=""#Fontane"" script=""Latf standard"" medium=""""/><handShift xmlns=""http://www.tei-c.org/ns/1.0"" new=""#Fontane"" script="""" medium=""""/><milestone xmlns=""http://www.tei-c.org/ns/1.0"" unit=""section"" type=""Text_1"" spanTo=""#C07_3r_s""/><handShift xmlns=""http://www.tei-c.org/ns/1.0"" script=""Latn clean"" new=""#Fontane"" medium=""""/><head xmlns=""http://www.tei-c.org/ns/1.0"" type=""x-large"" rend=""align(center)""><rs xmlns=""http://www.tei-c.org/ns/1.0"" type=""direct"" ref=""psn:Luther""><hi xmlns=""http://www.tei-c.org/ns/1.0"">Luther</hi></rs></head></body>")
%test:assertEquals("<body xmlns=""http://www.tei-c.org/ns/1.0""><milestone xmlns=""http://www.tei-c.org/ns/1.0"" unit=""line""/><milestone xmlns=""http://www.tei-c.org/ns/1.0"" unit=""section"" type=""Text_1"" spanTo=""#C07_3r_s""/><handShift xmlns=""http://www.tei-c.org/ns/1.0"" script=""Latn clean"" new=""#Fontane"" medium=""""/><head xmlns=""http://www.tei-c.org/ns/1.0"" type=""x-large"" rend=""align(center)""><rs xmlns=""http://www.tei-c.org/ns/1.0"" type=""direct"" ref=""psn:Luther""><hi xmlns=""http://www.tei-c.org/ns/1.0"">Luther</hi></rs></head></body>")
function tidysimple-test:handShift-surplus($node as element(*)) {
tidySimple:sort-out-surplus-hands($node)
......
......@@ -19,6 +19,7 @@ declare namespace test="http://exist-db.org/xquery/xqsuite";
import module namespace config="http://textgrid.de/ns/SADE/config" at "../../config/config.xqm";
import module namespace console="http://exist-db.org/xquery/console";
import module namespace functx="http://www.functx.com";
import module namespace simpleHelpers="http://fontane-nb.dariah.eu/teisimplehelpers" at "teisimplehelpers.xqm";
......@@ -40,7 +41,7 @@ declare function tidySimple:main($tei as node()*) as xs:string* {
let $clear-invalid-hands := tidySimple:sort-out-invalid-hands($text)
let $clear-surplus-hands := tidySimple:sort-out-surplus-hands($clear-invalid-hands)
let $text-with-sections := tidySimple:make-structure($clear-surplus-hands)
let $store := xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple-tmp.xml", <div>{$text-with-sections}</div>)
let $store := xmldb:store("/db/apps/SADE/resources/xml/", "tei-simple-tmp.xml", <div>{$clear-surplus-hands}</div>)
return ""
(: let $doc := doc($config:app-root || "/resources/xml/tei-simple-tmp.xml"):)
(: let $tidied-text := tidySimple:tidy($doc//tei:text):)
......@@ -101,7 +102,8 @@ as node()* {
$node
case element(tei:handShift) return
if(simpleHelpers:is-prev-hand-same($node)) then
if(simpleHelpers:is-prev-hand-same($node)
or not(tidySimple:has-hand-text($node))) then
()
else
tidySimple:copy-element($node, "surplus")
......@@ -113,6 +115,28 @@ as node()* {
}
};
declare function tidySimple:has-hand-text($node as element(tei:handShift))
as xs:boolean {
let $next-handshift := $node/following::tei:handShift[1]
let $nodes-between := $node/following::node()[. << $next-handshift]
let $is-text-node :=
for $node-between in $nodes-between
return
if ($node-between[self::text()]
and not(normalize-space($node-between) = "")) then
true()
else
false()
return
if($next-handshift
and functx:is-value-in-sequence(true(), $is-text-node)) then
true()
else if(not($next-handshift)) then
true()
else
false()
};
declare function tidySimple:copy-element($node as node(), $flag as xs:string)
{
......
This diff is collapsed.
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