输入 XML -
<?xml version="1.0"?>
<EsrOrder>
<Header>
<OrderId>
865975
</OrderId>
<Metadata>
None
</Metadata>
</Header>
<ESRBody>
<TN>
6543219785
</TN>
<Tntype>
Wireline
</Tntype>
<Priority>
High
</Priority>
<TnOwnerName>
Ching Chang
</TnOwnerName>
<TnAddress>
<BasicAddress>
101,Clssic View 44 Baikunth Dham Colony
</BasicAddress>
<Landmark>
Near Anand Bazar
</Landmark>
<City>
Indore
</City>
<State>
Madhya Pradesh
</State>
<Country>
India
</Country>
</TnAddress>
</ESRBody>
</EsrOrder>
使用 XSLT -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:copy>
<Sea_Element>
<xsl:apply-templates/>
</Sea_Element>
</xsl:copy>
</xsl:template>
<xsl:template match="EsrOrder/Header">
<xsl:copy-of select="@*|node()" />
</xsl:template>
<xsl:template match="EsrOrder/ESRBody">
<xsl:copy-of select="@*|node()" />
</xsl:template>
<!--<xsl:template match="EsrOrder/ESRBody/TnAddress">
<xsl:copy-of select="@*|node()" />
</xsl:template>-->
<xsl:template match="/*">
<xsl:apply-templates select="node()" />
</xsl:template>
</xsl:stylesheet>
我得到的输出 -
<?xml version="1.0" encoding="UTF-8"?>
<Sea_Element>
<OrderId>
865975
</OrderId>
<Metadata>
None
</Metadata>
<TN>
6543219785
</TN>
<Tntype>
Wireline
</Tntype>
<Priority>
High
</Priority>
<TnOwnerName>
Ching Chang
</TnOwnerName>
<TnAddress>
<BasicAddress>
101,Clssic View 44 Baikunth Dham Colony
</BasicAddress>
<Landmark>
Near Anand Bazar
</Landmark>
<City>
Indore
</City>
<State>
Madhya Pradesh
</State>
<Country>
India
</Country>
</TnAddress>
</Sea_Element>
哪里需要输出 -
<?xml version="1.0" encoding="UTF-8"?>
<Sea_Element>
<OrderId>
865975
</OrderId>
<Metadata>
None
</Metadata>
<TN>
6543219785
</TN>
<Tntype>
Wireline
</Tntype>
<Priority>
High
</Priority>
<TnOwnerName>
Ching Chang
</TnOwnerName>
<BasicAddress>
101,Clssic View 44 Baikunth Dham Colony
</BasicAddress>
<Landmark>
Near Anand Bazar
</Landmark>
<City>
Indore
</City>
<State>
Madhya Pradesh
</State>
<Country>
India
</Country>
</Sea_Element>
它只是一个没有被淘汰的父字段。即使相同的代码适用于其他要删除的标签,我也能得到原因并纠正 XSL....