开发者

How to copy everything as is and only remove a specific element

<?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 tryi开发者_运维问答ng 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 ?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜