這是我的XML與SOAP標題和正文:XSLT - 刪除前綴命名空間特定節點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">
這是XSLT
配置文件我有2版本中使用:
<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>
我要補充或修改,以去除該節點上的前綴?
你不能「刪除」命名空間前綴,在絕大多數情況下,你不需要做那樣的事情。你能解釋一下爲什麼你認爲這是必要的嗎? – Tomalak
由於我使用的WSDL,它需要@Tomalak – gtx911
對不起,這不是一個令人滿意的解釋。我問:「你爲什麼需要它?」你回答說:「因爲我需要它。」我認爲你需要給出一個比這更好的理由。 – Tomalak