Xslt删除以下格式的子元素的父元素。
<Response>
<Info>
<Info>
<Code>a</Code>
<Msg>fgh</Msg>
</Info>
<Info>
<Code>b</Code>
<Msg>ggh</Msg>
</Info>
</Info>
<Status>test</Status>
</Response>
需要以下格式的输出
<Response>
<Info>
<Code>a</Code>
<Msg>fgh</Msg>
</Info>
<Info>
<Code>b</Code>
<Msg>ggh</Msg>
</Info>
</Response>
如何使用xsl 获得以上格式
请尝试以下XSLT。
它使用的是所谓的身份转换模式。
输入XML
<Response>
<Info>
<Info>
<Code>a</Code>
<Msg>fgh</Msg>
</Info>
<Info>
<Code>b</Code>
<Msg>ggh</Msg>
</Info>
</Info>
<Status>test</Status>
</Response>
XSLT
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/Response/Info">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Status"/>
</xsl:stylesheet>
输出XML
<Response>
<Info>
<Code>a</Code>
<Msg>fgh</Msg>
</Info>
<Info>
<Code>b</Code>
<Msg>ggh</Msg>
</Info>
</Response>