Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
xquery version "3.0";
module namespace whitespace="http://bdn.edition.de/intermediate_format/whitespace_handling";
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 $single-whitespace-between-nodes := $text
[ self::node() = ' ']
[preceding-sibling::node()[not(self::node() = text())]]
[following-sibling::node()[not(self::node() = text())]]
return
if ( $normalized != "" or $single-whitespace-between-nodes) then (
if ($escape-char) then (
whitespace:escape-text($text, $escape-char)
) else ( whitespace:escape-text($text, " ") )
)
else ()
};
(:~
: string:escape-whitespace
: This function replaces whitespaces in a text()
: with one defined preservation character
:
: @version 1.0 (2017-09-14)
: @author Uwe Sikora
:)
declare function whitespace:escape-text
($text, $escape as xs:string) as text()* {
text {replace($text, '[\s]+', $escape)}
};