IBM Support

Removing empty attribute from an input XML file

Question & Answer


Question

How can I remove an empty attribute from an input XML file?

Answer

Use the XSLT below to remove empty attribute from the XML element:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="node()|SDLT">
<xsl:if test="count(descendant::text()[string-length(normalize-space(.))>0] | @*[string-length(.)>0])">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>
<xsl:template match="@*">
<xsl:if test="string-length(.)>0">
<xsl:copy/>
</xsl:if>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>
</xsl:stylesheet>

[{"Product":{"code":"SSGR73","label":"IBM Cast Iron Cloud Integration"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Not Applicable","Platform":[{"code":"PF016","label":"Linux"},{"code":"PF033","label":"Windows"},{"code":"PF009","label":"Firmware"},{"code":"PF025","label":"Platform Independent"}],"Version":"6.4.0.1;6.4.0.0;6.3.0.1;6.3;6.1.0.15;6.1.0.12;6.0.0.6;5.0.1.8","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Historical Number

00000644

Product Synonym

Cast Iron Solution
Cast Iron Operating System
Cast Iron Studio

Document Information

More support for:
IBM Cast Iron Cloud Integration

Software version:
6.4.0.1, 6.4.0.0, 6.3.0.1, 6.3, 6.1.0.15, 6.1.0.12, 6.0.0.6, 5.0.1.8

Operating system(s):
Linux, Windows, Firmware

Document number:
410697

Modified date:
15 June 2018

UID

swg21453180

Manage My Notification Subscriptions