{"id":35,"date":"2015-09-07T15:48:48","date_gmt":"2015-09-07T14:48:48","guid":{"rendered":"http:\/\/67bricks.com\/blog\/2015\/09\/07\/debugging-whitespace-issues-in-marklogic\/"},"modified":"2021-12-16T10:58:32","modified_gmt":"2021-12-16T10:58:32","slug":"debugging-whitespace-issues-in-marklogic","status":"publish","type":"post","link":"https:\/\/blog.67bricks.com\/?p=35","title":{"rendered":"Debugging whitespace issues in MarkLogic"},"content":{"rendered":"<p>I&#8217;ve just resolved a very confusing bug in some of our MarkLogic XQuery code. It ultimately turned out to be very simple to fix &#8211; just adding an &#8216;indent=no&#8217; parameter to the XSLT.<\/p>\n<p>However, there were three unexpected bits of behaviour that I encountered along the way, that made fixing it much harder than it should have been.<\/p>\n<p>First unexpected thing &#8211; MarkLogic was defaulting to &#8216;indent=yes&#8217; in its XSLT processing.<\/p>\n<p>Second unexpected thing &#8211; MarkLogic is applying its indent setting to the results of &lt;xsl:copy-of select=&#8221;.&#8221;\/&gt;. I expected &lt;textarea&gt;&lt;xsl:copy-of select=&#8221;.&#8221;\/&gt;&lt;\/textarea&gt; to give me an exact copy of the input, but it doesn&#8217;t, because indent is applied to it. Saxon doesn&#8217;t apply indent here, even if indent is set to yes.<\/p>\n<p>Third unexpected thing &#8211; MarkLogic&#8217;s QConsole can&#8217;t be trusted to display whitespace accurately. I displayed two almost identical documents in exactly the same way, via doc(&#8216;blah.xml&#8217;), in the console, and one of them was indented, and the other one wasn&#8217;t. These were the before-and-after documents for our &#8216;splitDocument&#8217; function, so I naturally thought that splitDocument was applying indentation. It was only when I wrote Scala code to retrieve the XML that I saw what was happening.<\/p>\n<p>Lessons:<\/p>\n<p>1) Always turn on indent=&#8217;no&#8217; in stylesheets used in MarkLogic<br \/>\n2) Don&#8217;t trust QConsole to debug whitespace issues. Instead, use code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve just resolved a very confusing bug in some of our MarkLogic XQuery code. It ultimately turned out to be very simple to fix &#8211; just adding an &#8216;indent=no&#8217; parameter to the XSLT. However, there were three unexpected bits of behaviour that I encountered along the way, that made fixing it much harder than it &hellip; <a href=\"https:\/\/blog.67bricks.com\/?p=35\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Debugging whitespace issues in MarkLogic&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-35","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=35"}],"version-history":[{"count":1,"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=\/wp\/v2\/posts\/35\/revisions"}],"predecessor-version":[{"id":310,"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=\/wp\/v2\/posts\/35\/revisions\/310"}],"wp:attachment":[{"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.67bricks.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}