Monday, 7 January 2013

Removing Empty Elements in XML using custom xslt , Biztalk

Remove empty elements from xml using custom xslt in biztalk Map.


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


Input XML :
<ns0:Root xmlns:ns0="http://BalanceList">
- <Header>
  <DocDate>20130102</DocDate>
  <ProdDate>20121228</ProdDate>
  </Header>
- <Detail>
  <EAN></EAN>
  <PartID>154002253</PartID>
  <Quantity>1</Quantity>
  <Batchnr></Batchnr>
  <QualityCode></QualityCode>
  <Ankdate>20121204</Ankdate>
  </Detail>
  </ns0:Root>


OutPut XML:
<ns0:Root xmlns:ns0="http://BalanceList">
- <Header>
  <DocDate>20130102</DocDate>
  <ProdDate>20121228</ProdDate>
  </Header>
- <Detail>
  <PartID>154002253</PartID>
  <Quantity>1</Quantity>
  <Ankdate>20121204</Ankdate>
  </Detail>
  </ns0:Root>

No comments:

Post a Comment