我希望将以下 xml 中的命名空间 v1 从http://choby.co.xx/DialogueServices/AM/V1 替换为http://choby.co.xx/XYZ/WM/V1
Input
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v1="http://choby.co.xx/DialogueServices/AM/V1">
<soapenv:Header/>
<soapenv:Body>
<v1:CancelAppointmentRequest>
<Loc>1</Loc>
</v1:CancelAppointmentRequest>
</soapenv:Body>
</soapenv:Envelope>
Expected:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v1="http://choby.co.xx/XYZ/WM/V1">
<soapenv:Header/>
<soapenv:Body>
<v1:CancelAppointmentRequest>
<Loc>1</Loc>
</v1:CancelAppointmentRequest>
</soapenv:Body>
</soapenv:Envelope>
使用的 xslt:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="http://choby.co.xx/XYZ/WM/V1"
xmlns:ns1old="http://choby.co.xx/DialogueServices/AM/V1">
<xsl:output omit-xml-declaration="no" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="/*">
<xsl:element name="soapenv:{local-name()}" namespace="http://www.w3.org/2003/05/soap-envelope">
<xsl:apply-templates select="node()|@*" />
</xsl:element>
</xsl:template>
<xsl:template match="ns1old:*">
<xsl:element name="ns1:{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Result:
<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"/>
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<ns1:CancelAppointmentRequest xmlns:ns1="http://choby.co.xx/XYZ/WM/V1">
<Loc>1</Loc>
</ns1:CancelAppointmentRequest>
</soapenv:Body>
</soapenv:Envelope>
Header 和 Body 命名空间与 Envelope 不同