tags:

views:

19

answers:

1

Hello all I have a webservice that returns an XML like this:

<?xml version="1.0" encoding="UTF-8"?>
<contractInformation>
    <contract>
        <idContract type="int">87191827</idContract>        
        <region type="varchar">null</region>
        <dueDate type="varchar">null</dueDate>
        <contactName type="varchar">John Smith</contactName>
    </contract>
</contractInformation>

I want to empty every tag that contains the string null, so it would look like this:

<?xml version="1.0" encoding="UTF-8"?>
<contractInformation>
    <contract>
        <idContract type="int">87191827</idContract>        
        <region type="varchar"/>
        <dueDate type="varchar"/>
        <contactName type="varchar">John Smith</contactName>
    </contract>
</contractInformation>

How do I accomplish that by using XSLT?

+3  A: 

Use and override the identity rule:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="node()|@*">
  <xsl:copy>
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
 </xsl:template>

 <xsl:template match="text()[.='null']"/>
</xsl:stylesheet>
Dimitre Novatchev