user3010912
user3010912

Reputation: 391

Add SOAP envelope and namespace prefix with XSLT

I have an input XML

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

that I need to manipulate into the following request.

    <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>

I'm trying to figure out how to add a namespace prefix ('ser') to a root tag only and leave the rest of them "as is", and at the same time add the SOAP around.

Upvotes: 0

Views: 5405

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 116992

How about simply:

<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>

Upvotes: 1

Related Questions