【发布时间】:2016-11-14 12:58:23
【问题描述】:
这是我的带有 SOAP 标头和正文的 XML:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<RequestResponse xmlns="http://tempuri.org/">
<a:RequestResult xmlns:a="http://schemas.datacontract.org/2004/07/MockupTesting"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Message>Message text testing.</a:Message>
<a:Response>false</a:Response>
</a:RequestResult>
</RequestResponse>
</s:Body>
</s:Envelope>
我需要仅删除 RequestResult 节点中的前缀。
从此
<a:RequestResult xmlns:a="http://schemas.datacontract.org/2004/07/MockupTesting"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
收件人:
<RequestResult xmlns:a="http://schemas.datacontract.org/2004/07/MockupTesting"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
这是我在版本 2 中使用的XSLT 配置文件:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<xsl:apply-templates />
</s:Body>
</s:Envelope>
</xsl:template>
<xsl:template match="RequestResult |RequestResult//*">
<xsl:element name="a:{name()}"
namespace="http://schemas.datacontract.org/2004/07/Testing">
<xsl:namespace name="a"
select="'http://schemas.datacontract.org/2004/07/MockupTesting'" />
<xsl:namespace name="i"
select="'http://www.w3.org/2001/XMLSchema-instance'" />
<!-- <xsl:copy-of select="namespace::*" /> -->
<xsl:apply-templates select="node()|@*" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
我应该添加或修改什么来删除该节点上的前缀?
【问题讨论】:
-
您不能“删除”命名空间前缀,而且在绝大多数情况下,您不必做类似的事情。你能解释一下为什么你认为在你的情况下这是必要的吗?
-
因为我消费的WSDL,需要@Tomalak
-
对不起,这不是一个令人满意的解释。我问:“你为什么需要它?”你回答“因为我需要它”。我认为你需要给出一个比这更好的理由。
标签: xml xslt xml-namespaces prefix