<?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>
Run Code Online (Sandbox Code Playgroud)
我只是想复制所有元素,包括命名空间但没有 <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>
Run Code Online (Sandbox Code Playgroud)
我用了
<xsl:template match='/'>
<xsl:copy-of select='@*[not(Det:EmpExperience)]'/>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
它没有工作:-( ...这个PLZ的任何解决方案.
如何只删除<Det:EmpExperience>元素并复制其余元素,包括命名空间?
试试这个(改编自这里):
<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>
Run Code Online (Sandbox Code Playgroud)
第二个模板覆盖标识转换,空模板使用匹配逻辑(选择Det:EmpExperience节点).
| 归档时间: |
|
| 查看次数: |
3228 次 |
| 最近记录: |