Aqui está meu XML:
<?xml version='1.0' encoding='utf-8'?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<wd:Unpost_Job_Request
xmlns:wd="urn:com.test.report"
wd:version="v40.2">
<wd:Business_Process_Parameters>
<wd:Auto_Complete>true</wd:Auto_Complete>
<wd:Run_Now>true</wd:Run_Now>
<wd:Discard_On_Exit_Validation_Error>true</wd:Discard_On_Exit_Validation_Error>
<wd:Comment_Data>
<wd:Comment>Unposting Triggered by Automation</wd:Comment>
</wd:Comment_Data>
</wd:Business_Process_Parameters>
<wd:Unpost_Job_Data>
<wd:Job_Posting_Reference>
<wd:ID wd:type="Job_Posting_ID">JOB_POSTING-3-23427</wd:ID>
</wd:Job_Posting_Reference>
</wd:Unpost_Job_Data>
</wd:Unpost_Job_Request>
</env:Body>
</env:Envelope>
Preciso copiar todo o documento e alterar apenas o seguinte namespace:
<wd:Unpost_Job_Request
xmlns:wd="urn:com.test.report" <-- Changed to xmlns:wd="urn:com.final.report"
wd:version="v40.2">
Portanto, o resultado final esperado seria:
<?xml version='1.0' encoding='utf-8'?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<wd:Unpost_Job_Request
xmlns:wd="urn:com.final.report"
wd:version="v40.2">
<wd:Business_Process_Parameters>
<wd:Auto_Complete>true</wd:Auto_Complete>
<wd:Run_Now>true</wd:Run_Now>
<wd:Discard_On_Exit_Validation_Error>true</wd:Discard_On_Exit_Validation_Error>
<wd:Comment_Data>
<wd:Comment>Unposting Triggered by Automation</wd:Comment>
</wd:Comment_Data>
</wd:Business_Process_Parameters>
<wd:Unpost_Job_Data>
<wd:Job_Posting_Reference>
<wd:ID wd:type="Job_Posting_ID">JOB_POSTING-3-23427</wd:ID>
</wd:Job_Posting_Reference>
</wd:Unpost_Job_Data>
</wd:Unpost_Job_Request>
</env:Body>
</env:Envelope>
Aqui está meu XSL atual:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wd="urn:com.test.report"
exclude-result-prefixes="xs" version="2.0">
<xsl:output indent="yes" method="xml" encoding="utf-8" omit-xml-declaration="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="wd:Unpost_Job_Request">
<xsl:element name="{local-name(.)}">
<xsl:namespace name="wd">urn:com.final.report</xsl:namespace>
<xsl:apply-templates select="node() | @*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
O que retorna:
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<Unpost_Job_Request xmlns:wd="urn:com.final.report"
xmlns:wd_1="urn:com.test.report"
wd_1:version="v40.2">
<wd:Business_Process_Parameters xmlns:wd="urn:com.test.report">
<wd:Auto_Complete>true</wd:Auto_Complete>
<wd:Run_Now>true</wd:Run_Now>
<wd:Discard_On_Exit_Validation_Error>true</wd:Discard_On_Exit_Validation_Error>
<wd:Comment_Data>
<wd:Comment>Unposting Triggered by Automation</wd:Comment>
</wd:Comment_Data>
</wd:Business_Process_Parameters>
<wd:Unpost_Job_Data xmlns:wd="urn:com.test.report">
<wd:Job_Posting_Reference>
<wd:ID wd:type="Job_Posting_ID">JOB_POSTING-3-23427</wd:ID>
</wd:Job_Posting_Reference>
</wd:Unpost_Job_Data>
</Unpost_Job_Request>
</env:Body>
</env:Envelope>
Portanto, em vez de substituir o URI xmlns:wd existente, ele está adicionando um novo namespace líquido e anexando "_1" ao antigo e, em seguida, adicionando um xmlns:wd indesejado a outro elemento. Tentei algumas soluções encontradas aqui, mas a acima foi o mais próximo que cheguei do meu objetivo. Outras soluções adicionam um namespace adicional.
Para obter o resultado exato mostrado, você teria que mover TODOS os elementos e atributos do namespace antigo para o novo namespace: