Skip to content
Snippets Groups Projects
Unverified Commit 7d3b8bb3 authored by MRodz's avatar MRodz Committed by GitHub
Browse files

added further preprocessing for whitespaces

parent 3d0815f7
No related branches found
No related tags found
No related merge requests found
xquery version "3.0";
(:~
(:~
: PREPROCESSING Module ("pre", "http://bdn.edition.de/intermediate_format/preprocessing")
: *******************************************************************************************
: This module contains the preprocessing routines for the intermediate format
:
: It imports the whitespace handling helper module to make some whitespace handling duricng the preprocessing
: @version 2.0 (2018-01-29)
: @status working
: @author Uwe Sikora
......@@ -18,20 +18,20 @@ declare default element namespace "http://www.tei-c.org/ns/1.0";
(:############################# Modules Functions #############################:)
(:~
(:~
: pre:preprocessing-textNode
: preprocessing function which converts each text() into a xml-node "textNode". This function is a experimental fall back solution and not the main preprocessing routine!
:
: @param $nodes the nodes to be converted
: @return item()* representing the converted node
:
:
: @version 1.2 (2017-10-15)
: @status working
: @author Uwe Sikora
:)
declare function pre:preprocessing-textNode
($nodes as node()*) as item()* {
for $node in $nodes
return
typeswitch($node)
......@@ -44,7 +44,7 @@ declare function pre:preprocessing-textNode
}
)
)
case element(TEI) return (
element{$node/name()}{
$node/@*,
......@@ -54,7 +54,7 @@ declare function pre:preprocessing-textNode
}
}
)
case element(lem) return (
element{$node/name()}{
$node/@*,
......@@ -62,7 +62,7 @@ declare function pre:preprocessing-textNode
pre:preprocessing-textNode($node/node())
}
)
case element(rdg) return (
element{$node/name()}{
$node/@*,
......@@ -70,7 +70,7 @@ declare function pre:preprocessing-textNode
pre:preprocessing-textNode($node/node())
}
)
case element(note) return (
if ($node[@type eq "editorial"]) then (
) else (
......@@ -80,8 +80,8 @@ declare function pre:preprocessing-textNode
}
)
)
default return (
default return (
element{$node/name()}{
$node/@*,
pre:preprocessing-textNode($node/node())
......@@ -90,7 +90,7 @@ declare function pre:preprocessing-textNode
};
(:~
(:~
: pre:pre:default-element
: function that suites as default element constructor for the preproseccing conversion.
: It is more or less a copy function, copying the elements name and its node and recurively leeds the conversion to its child-nodes
......@@ -98,7 +98,7 @@ declare function pre:preprocessing-textNode
: @param $node the node to be copied
: @param $recursive-function the recursive function as some kind of call back to the main conversion
: @return item()* representing the converted node
:
:
: @version 1.0 (2018-01-31)
: @note Would be great if $recursive-function would be a real function and not a node-sequence (TO-DO)
: @status working
......@@ -106,39 +106,49 @@ declare function pre:preprocessing-textNode
:)
declare function pre:default-element
( $node as node(), $recursive-function as node()* ) as item()* {
element{$node/name()}{
$node/@*,
$recursive-function
}
let $following-node := $node/following-sibling::node()[1]
let $following-sibling := $node/following-sibling::*[1]
return
element{$node/name()}{
$node/@*,
(if($following-node[matches(., "[\s\n\r\t]") and normalize-space(.) = ""]
and $following-sibling[self::ref or self::app or self::hi or self::bibl
or self::foreign or self::choice or self::milestone or self::persName
or self::choice or self::index]
and not($node[self::index]))
then
attribute {"break-after"}{"yes"}
else ()),
$recursive-function
}
};
(:~
(:~
: pre:preprocessing
: main preprocessing function.
:
: @param $nodes the nodes to be converted
: @return item()* representing the converted node
:
:
: @version 2.0 (2018-02-01)
: @status working
: @author Uwe Sikora
:)
declare function pre:preprocessing
($nodes as node()*) as item()* {
for $node in $nodes
return
typeswitch($node)
case processing-instruction() return ()
case text() return (
whitespace:text($node, " ")
)
case comment() return ()
case element(TEI) return (
element{$node/name()}{
$node/@*,
......@@ -150,19 +160,19 @@ declare function pre:preprocessing
}
}
)
case element(teiHeader) return ( $node )
case element(div) return (
if ($node[@type = 'section-group']) then (
pre:preprocessing($node/node())
)
)
else (
pre:default-element( $node, pre:preprocessing($node/node()) )
)
)
case element(lem) return (
element{$node/name()}{
$node/@*,
......@@ -170,7 +180,7 @@ declare function pre:preprocessing
pre:preprocessing($node/node())
}
)
case element(rdg) return (
element{$node/name()}{
$node/@*,
......@@ -178,87 +188,118 @@ declare function pre:preprocessing
pre:preprocessing($node/node())
}
)
case element(note) return (
if ( $node[@type != "editorial"] or $node[ not(@type) ] ) then (
pre:default-element( $node, pre:preprocessing($node/node()) )
) else ( )
)
case element(pb) return (
let $preceding-sibling := $node/preceding-sibling::node()[1]
let $following-sibling := $node/following-sibling::node()[1]
let $following-element := $node/following::*[1]
let $first := $node = $node/parent::node()/node()[not(self::text() and normalize-space(self::node()) = '')][1]
let $ignore := ("docAuthor", "app", "index", "seg", "bibl")
return
element {$node/name()}{
$node/@*,
if (
if (
( $preceding-sibling[self::text() and not(normalize-space(.) = '')] and ends-with($preceding-sibling, " ") = false() )
and
( $following-sibling[self::text() and not(normalize-space(.) = '')] and starts-with($following-sibling, " ") = false() )
) then ( attribute {"break"}{"no"} )
(:else if (
) then ( attribute {"break"}{"no"} )
(:else if (
( $preceeding-sibling[self::text() and not(normalize-space(.) = '')] and ends-with($preceeding-sibling, " ") = true() )
and
( $following-sibling[self::text() and not(normalize-space(.) = '')] and starts-with($following-sibling, " ") = true() )
) then ( attribute {"clear"}{"left"} ) :)
(:else if ( $following-sibling[self::docAuthor or self::app or self::index or self::seg or self::bibl] ) then (
attribute {"break"}{"yes"}
):)
else if (
else if (
( $preceding-sibling[matches(., "[\s\n\r\t]") and normalize-space(.) = ""] )
and
( $following-sibling[matches(., "[\s\n\r\t]") and normalize-space(.) = ""] )
) then (
attribute {"break"}{"yes"}
attribute {"break-before"}{"yes"},
attribute {"break-after"}{"yes"}
)
else if (
$preceding-sibling[matches(., "[\s\n\r\t]") and normalize-space(.) = ""]
) then (
attribute {"break-before"}{"yes"}
)
else if (
$following-sibling[matches(., "[\s\n\r\t]") and normalize-space(.) = ""]
) then (
attribute {"break-after"}{"yes"}
)
else ( )
}
)
case element(hi) return (
if($node[@rend = 'right-aligned' or @rend = 'center-aligned']) then(
if($node[@rend = 'right-aligned' or @rend = 'center-aligned']) then(
element {'aligned'} {
$node/@*,
pre:preprocessing($node/node())
}
}
)
else (
pre:default-element( $node, pre:preprocessing($node/node()) )
)
)
case element(seg) return (
if($node[@type = 'item']) then(
element {'item'} {
$node/@*[name() != 'type'],
pre:preprocessing($node/node())
}
}
)
else if($node[@type = 'head']) then(
element {'head'} {
$node/@*[name() != 'type'],
pre:preprocessing($node/node())
}
}
)
else if($node[@type = 'row']) then(
element {'row'} {
$node/@*[name() != 'type'],
pre:preprocessing($node/node())
}
}
)
else (
pre:default-element( $node, pre:preprocessing($node/node()) )
)
)
default return (
case element(ref) return (
whitespace:set-additional-whitespace($node)
)
case element(app) return (
whitespace:set-additional-whitespace($node)
)
case element(bibl) return (
whitespace:set-additional-whitespace($node)
)
case element(foreign) return (
whitespace:set-additional-whitespace($node)
)
case element(p) return (
whitespace:set-additional-whitespace($node)
)
case element(choice) return (
whitespace:set-additional-whitespace($node)
)
default return (
pre:default-element( $node, pre:preprocessing($node/node()) )
)
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment