diff --git a/modules/intermediate_format/whitespace-handling.xqm b/modules/intermediate_format/whitespace-handling.xqm
index cd2a09e31fb4961478fea7d19041b28b052ba5ea..7cd0209cbc9b2df72c14cffdf7b112459524fef8 100644
--- a/modules/intermediate_format/whitespace-handling.xqm
+++ b/modules/intermediate_format/whitespace-handling.xqm
@@ -31,9 +31,9 @@ declare function whitespace:text
     ( $text as text()*, $escape-char as xs:string? ) as text()* {
 
     let $whitespace-node := $text[matches(., "[\s\n\r\t]") and normalize-space(.) = ""]
-    let $single-whitespace-between-nodes := $text = ' '
+    let $single-whitespace-between-nodes := $text = " "
     return
-        if ( not($whitespace-node) or $single-whitespace-between-nodes) then (
+        if (not($whitespace-node)) then (
 
             if ($escape-char) then (
                 whitespace:escape-text($text, "@")
@@ -63,3 +63,16 @@ declare function whitespace:escape-text
 
     text {replace($text, '[\s]+', $escape)}
 };
+
+declare function whitespace:remove($nodes as node()*) as node()* {
+    for $node in $nodes
+    return
+        typeswitch ($node)
+        case text() return
+            if([matches($node, "[\s\n\r\t]") and normalize-space(.) = ""]) then 
+                ()
+            else
+                $node
+        default return
+            $node
+};