5
<?xml version="1.0" encoding="UTF-8"?>
<Emp:Employee xmlns:Emp="http://Emp.com">
    <Emp:EmpName>XYZ</Emp:EmpName>
    <Emp:EmpAddres>AAAA</Emp:EmpAddres>
    <Det:EmpDetails xmlns:Det="http://Det.com">
        <Det:EmpDesignation>SE</Det:EmpDesignation>
        <Det:EmpExperience>4</Det:EmpExperience>
    </Det:EmpDetails>
</Emp:Employee>

I am just trying to copy all the elements including the namespace but without <Det:EmpExperience>4</Det:EmpExperience>

so the final output should be :

<?xml version="1.0" encoding="UTF-8"?>
    <Emp:Employee xmlns:Emp="http://Emp.com">
        <Emp:EmpName>XYZ</Emp:EmpName>
        <Emp:EmpAddres>AAAA</Emp:EmpAddres>
        <Det:EmpDetails xmlns:Det="http://Det.com">
            <Det:EmpDesignation>SE</Det:EmpDesignation>
         </Det:EmpDetails>
    </Emp:Employee>

I used

<xsl:template match='/'>
<xsl:copy-of select='@*[not(Det:EmpExperience)]'/>
</xsl:template>

its not working :-( ... any solution for this plz.

how to remove only <Det:EmpExperience> element and copy rest of the elements including namespace ?

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
Madhu CM
  • 2,296
  • 6
  • 29
  • 38
  • possible duplicate of [How to remove elements from xml using xslt with stylesheet and xsltproc?](http://stackoverflow.com/questions/321860/how-to-remove-elements-from-xml-using-xslt-with-stylesheet-and-xsltproc) –  Dec 06 '10 at 13:34

1 Answers1

7

Try this (adapted from here):

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:Det="http://Det.com">

 <xsl:output omit-xml-declaration="yes"/>

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

    <xsl:template match="Det:EmpExperience"/>
</xsl:stylesheet>

The second template overrides the identity transformation and the empty template uses your matching logic (selecting Det:EmpExperience nodes).

Community
  • 1
  • 1
Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • @Madhu CM - note that I forgot the `xmlns:Det="http://Det.com"` declaration in my answer earlier. Updated and tested... – Oded Dec 06 '10 at 08:35