BizTalk 2013 Issue: White space cannot be stripped from input documents that have already been loaded. Provide the input document as an XmlReader instead.

I noted this issue with BizTalk 2013 map. There is a BizTalk 2010 Application which uses XSLT to strip off empty elements. This XSLT uses <xsl:strip-space elements=”*”/>  element.

Here is the XSLT which works fine in BizTalk 2010.

<xsl:stylesheet version=”1.0″
xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>
<xsl:output omit-xml-declaration=”yes” indent=”yes”/>
<xsl:strip-space elements=”*”/>
<xsl:template match=”node()|@*”>
<xsl:copy>
<xsl:apply-templates select=”node()|@*”/>
</xsl:copy>
</xsl:template>
<xsl:template match=”*[not(*) and not(text()[normalize-space()]) and not(@*)]”/>
</xsl:stylesheet>

 However this XSLT will fail in 2013 with an error

“XSL transform error: Unable to write output instance to the following file. Exception has been thrown by the target of an invocation. White space cannot be stripped from input documents that have already been loaded. Provide the input document as an XmlReader instead.”

Reason for this is simple – BizTalk 2013 uses Compiled XSL Transform class.  Solution for this is to another XSLT which does not use xsl:strip-space element which is posted here.

<xsl:output omit-xml-declaration=”yes” indent=”yes”/>
<xsl:template match=”node()”>
<xsl:if test=”count(descendant::text()[string-length(normalize-space(.))>0]|@*)”>
<xsl:copy>
<xsl:apply-templates select=”@*|node()”/>
</xsl:copy>
</xsl:if>
</xsl:template>
<xsl:template match=”@*”>
<xsl:copy/>
</xsl:template>
<xsl:template match=”text()”>
<xsl:value-of select=”normalize-space(.)”/>
</xsl:template>

Hope this helps.

– Shiv

One Platform Operations, Monitoring and Analytics Software
BizTalk360

microsoft biztalk

Learn more

Over 500 customers across 30+ countries depend on BizTalk360

ServiceBus360

Azure service bus

Learn more

Start managing your Azure Service Bus namespaces in minutes

One Platform - Operations, Monitoring and Analytics Software
BizTalk360

microsoft biztalk

Learn more

Over 500 customers across 30+ countries depend on BizTalk360

One Platform - Operations, Monitoring and Analytics Software
ServiceBus360

Azure service bus

Learn more

Start managing your Azure Service Bus namespaces in minutes

Back to Top