Remove all empty nodes from xml using xslt

Empty nodes in xml payload increase the size of the xml and may cause in parser errros.

For big XML payloads you can use a separate XSLT transformation to handle all the empty nodes.

XSLT transformation –>

<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>

  • Drag and drop a Transform activity and select the XML payload, from which you want to remove empty nodes. Select same XML document for source and target.
  • Create an empty transformation and replace the XSLT fragment given below with the above.

<xsl:template match=”/”>

</xsl:template>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s