使用XSLT添加SOAP信封和名称空间前缀

时间:2015-07-09 18:59:59

标签: xml xslt soap

我有一个输入XML

<declarationBillingRecordRequest>
    <requestId>2</requestId>
    <declarations>
        <declarantTin>200000328-1</declarantTin>
    </declarations>
</declarationBillingRecordRequest>

我需要操纵以下请求。

    <soapenv:Envelope xmlns:ser="http://asycuda.tatisint.com/services" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header/>
    <soapenv:Body>
        <ser:declarationBillingRecordRequest>
            <requestId>2</requestId>
            <declarations>
                <declarantTin>200000328-1</declarantTin>
            </declarations>
        </ser:declarationBillingRecordRequest>
    </soapenv:Body>
</soapenv:Envelope>

我正在试图弄清楚如何仅将命名空间前缀('ser')添加到根标记中,并将其余部分“按原样”保留,同时添加SOAP。

1 个答案:

答案 0 :(得分:1)

简单地说:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ser="http://asycuda.tatisint.com/services"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/declarationBillingRecordRequest">
    <soapenv:Envelope>
        <soapenv:Header/>
        <soapenv:Body>
            <ser:declarationBillingRecordRequest>
                <xsl:copy-of select="*"/>
            </ser:declarationBillingRecordRequest>
        </soapenv:Body>
    </soapenv:Envelope>
</xsl:template>

</xsl:stylesheet>