xsl:复制除父节点之外的整个xml但保留其子节点 [英] xsl: Copy the entire xml except a parent node but keep its child node
本文介绍了xsl:复制除父节点之外的整个xml但保留其子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想复制整个 XML 文档但删除一个父节点.但是,这个父节点还有一个我想保留的子节点.
I want to copy the entire XML document but remove a parent node. However this parent node also has a child that I'd like to keep.
要删除的节点是
,要保留的子节点是
.
The node to remove is <LoginID>
and the child node to keep is <PAN>
.
<InqRs>
<LoginID> <!-- remove -->
<PAN>4506445</PAN> <!-- keep -->
</LoginID>
<RqUID>93</RqUID>
<Dt>90703195116</Dt>
<CaptureDate>704</CaptureDate>
<ApprovalCode>934999</ApprovalCode>
<StatusCode>000</StatusCode>
<List>
<Count>9</Count>
<AddDataFlag>N</AddDataFlag>
<Use>C</Use>
<DetRec>
<ID>007237048637</ID>
<Type1>62</Type1>
<Qual />
<ID>0010</ID>
<Status>1</Status>
<InqFlag>Y</InqFlag>
</DetRec>
</List>
</InqRs>
推荐答案
这个 XSL 应该能满足需要.
This XSL should do the needful.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="InqRs/LoginID">
<xsl:copy-of select="@*|node()" />
</xsl:template>
</xsl:stylesheet>
这篇关于xsl:复制除父节点之外的整个xml但保留其子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文