【发布时间】:2016-03-04 21:27:09
【问题描述】:
有这个 XML,我需要删除所有前缀,我之前做过,但是有一个特定的 NS2 前缀我无法删除。
检查:
输入 XML
<NS1:Envelope xmlns:NS1="http://schemas.xmlsoap.org/soap/envelope/">
<NS1:Header>
<NS2:responseHeader xmlns:NS2="http://test.com">
<systemId>SI</systemId>
<messageId>000001</messageId>
<timestamp>2015-01-16T10:10:09.872983</timestamp>
<responseStatus>
<statusCode>Success</statusCode>
</responseStatus>
</NS2:responseHeader>
</NS1:Header>
<NS1:Body>
<NS2:modificarSolicitudDeCreditoResponse xmlns:NS2="http://test2.com/21"/>
</NS1:Body>
</NS1:Envelope>
我的 XSLT:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="NS2:modificarSolicitudDeCreditoResponse">
<modificarSolicitudDeCreditoResponse>
<xsl:apply-templates select="@*|node()"/>
</modificarSolicitudDeCreditoResponse>
</xsl:template>
<xsl:template match="NS1:Header">
<Header>
<xsl:apply-templates select="@*|node()"/>
</Header>
</xsl:template>
<xsl:template match="NS2:responseHeader">
<responseHeader>
<xsl:apply-templates select="@*|node()"/>
</responseHeader>
</xsl:template>
<xsl:template match="NS1:Body">
<Body>
<xsl:apply-templates select="@*|node()"/>
</Body>
</xsl:template>
<xsl:template match="/*">
<Envelope>
<xsl:apply-templates select="node()" />
</Envelope>
</xsl:template>
</xsl:stylesheet>
这是我的输出:
<?xml version='1.0' ?>
<Envelope xmlns:NS1="http://schemas.xmlsoap.org/soap/envelope/"
<Header>
<responseHeader>
<systemId>AW0856</systemId>
<messageId>0000012</messageId>
<timestamp>2015-01-16T10:10:09.872983</timestamp>
<responseStatus>
<statusCode>Success</statusCode>
</responseStatus>
</responseHeader>
</Header>
<Body>
<NS2:modificarSolicitudDeCreditoResponse xmlns:NS2="http://test2.com/21">
</Body>
</Envelope>
我在删除 body 标签后的 NS2 时遇到问题,有谁知道我如何实现这一点, 谢谢
【问题讨论】:
-
请发布您期望得到的确切输出。
标签: xml xslt namespaces output