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

added further preprocessing for whitespaces

parent 7d3b8bb3
No related branches found
No related tags found
No related merge requests found
xquery version "3.0";
(:~
(:~
: WHITESPACE Module ("whitespace", "http://bdn.edition.de/intermediate_format/whitespace_handling")
: *******************************************************************************************
: This module contains the functions to handle different whitespace operations on text
......@@ -9,12 +9,14 @@ xquery version "3.0";
: @author Uwe Sikora
:)
module namespace whitespace="http://bdn.edition.de/intermediate_format/whitespace_handling";
import module namespace pre="http://bdn.edition.de/intermediate_format/preprocessing" at "preprocessing.xqm";
declare default element namespace "http://www.tei-c.org/ns/1.0";
(:############################# Modules Functions #############################:)
(:~
(:~
: whitespace:text()
: This function handles whitespace in defined text() nodes
:
......@@ -28,26 +30,26 @@ declare default element namespace "http://www.tei-c.org/ns/1.0";
:)
declare function whitespace:text
( $text as text()*, $escape-char as xs:string? ) as text()* {
let $normalized := normalize-space($text)
let $whitespace-node := $text[matches(., "[\s\n\r\t]") and normalize-space(.) = ""]
let $single-whitespace-between-nodes := $text = ' '
return
return
if ( not($whitespace-node) or $single-whitespace-between-nodes) then (
if ($escape-char) then (
whitespace:escape-text($text, "#")
whitespace:escape-text($text, "#")
) else ( whitespace:escape-text($text, " ") )
)
)
else ()
};
(:~
(:~
: whitespace:escape-text()
: This function replaces whitespaces in a text()
: This function replaces whitespaces in a text()
: with a defined preservation character
:
: @param $text the text-node to be converted
......@@ -63,3 +65,32 @@ declare function whitespace:escape-text
text {replace($text, '[\s]+', $escape)}
};
(:~
: whitespace:set-additional-whitespace()
: This function creates a "break-after"-attribute for a node, that has to be
: followed by a whitespace in PDF.
:
:
: @param $node the current node
: @return node() the new node with an attribute where necessary
:
: @version 1.0 (2018-02-13)
: @status working
: @author Michelle Rodzis
:)
declare function whitespace:set-additional-whitespace($node as node()) as node() {
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])
then
attribute {"break-after"}{"yes"}
else ()),
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