SAP is sending Empty Elements in XML Payload (IDOC). We need to remove the Empty Elements (<E1EDK02 SEGMENT="1"></E1EDK02>) in the IDOC below from the payload. I have used an XSLT script to remove these empty elements but still I see with the below XSLT, the Empty Elements are not removed but they are converted to <E1EDK02 SEGMENT="1"/>. Can anyone help us with the XSLT code which removes Empty.
IDOC From SAP
<?xml version="1.0" encoding="UTF-8"?><ORDERS05>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<TABNAM>XXX</TABNAM>
<MANDT>XXX</MANDT>
<IDOCTYP>XXX</IDOCTYP>
</EDI_DC40>
<E1EDK02 SEGMENT="1">
<QUALF>001</QUALF>
<BELNR>TEST</BELNR>
<DATUM>20210317</DATUM>
</E1EDK02>
<E1EDK02 SEGMENT="1"></E1EDK02>
<E1EDK02 SEGMENT="1">
<QUALF>002</QUALF>
<BELNR>TEST</BELNR>
<DATUM>20210317</DATUM>
</E1EDK02>
<E1EDK02 SEGMENT="1"></E1EDK02>
</IDOC></ORDERS05>
XSLT used
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes" />
<xsl:template match="@*|node()">
<xsl:if test=". != '' or ./@* != ''">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:template></xsl:stylesheet>
Expected Output
<?xml version="1.0" encoding="UTF-8"?><ORDERS05>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<TABNAM>XXX</TABNAM>
<MANDT>XXX</MANDT>
<IDOCTYP>XXX</IDOCTYP>
</EDI_DC40>
<E1EDK02 SEGMENT="1">
<QUALF>001</QUALF>
<BELNR>TEST</BELNR>
<DATUM>20210317</DATUM>
</E1EDK02>
<E1EDK02 SEGMENT="1">
<QUALF>002</QUALF>
<BELNR>TEST</BELNR>
<DATUM>20210317</DATUM>
</E1EDK02>
</IDOC></ORDERS05>