如何按原样复制所有内容并仅删除特定元素 [英] How to copy everything as is and only remove a specific element

查看:26
本文介绍了如何按原样复制所有内容并仅删除特定元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我只是想复制包括命名空间在内的所有元素,但没有 <Det:EmpExperience>4</Det:EmpExperience>

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

所以最终输出应该是:

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

我用过

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

第二个模板覆盖身份转换,空模板使用您的匹配逻辑(选择 Det:EmpExperience 节点).

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

这篇关于如何按原样复制所有内容并仅删除特定元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆