Thursday, May 28, 2020

XSLT template to remove null values from xml


This simple xquery can help to remove null fields and map only fields with values in any xml.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="@*|node()">
      <xsl:if test="normalize-space(.)!='' or ./@* != ''">
        <xsl:copy>
           <xsl:copy-of select="@*"/>
           <xsl:apply-templates/>
        </xsl:copy>
      </xsl:if>
   </xsl:template>
</xsl:stylesheet>

No comments:

Post a Comment