Click to See Complete Forum and Search --> : problem copying namespace information when using xsl transformation


abbi
05-18-2010, 05:28 PM
Hi I have an xml which is :

-------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-16"?>
<FareSearchRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" TestMode="false" MaskPassengerData="false" AllowDifferentBeginAndEndAirports="false">
<Credentials AccountNumber="" Login="test" Password="test" />
<MaxPrice Amount="0" CurrencyCode="USD" />
<Passengers>
<Passenger CustomerPassengerID="" FirstName="first" LastName="last" Key="0" />
</Passengers>
</FareSearchRequest>
-------------------------------------------------------------------------



Now I want to wrap it with Soap. I have this xslt (StyleSheetTowrapwithSoap.txt) but it does not copy the name space information which I really need.

------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" >
<xslutput method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:call-template name="WrapWithSoap">
<xsl:with-param name="METHOD">
<xsl:copy-of select="./*" />
</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template name="WrapWithSoap">
<xslaram name="METHOD"/>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<xsl:copy-of select="$METHOD"/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</xsl:template>
</xsl:stylesheet>
------------------------------------------------------------------------

So the Output is like this:

<FareSearchRequest TestMode="false" MaskPassengerData="false" AllowDifferentBeginAndEndAirports="false">........ .

But I want it to be like this:

<FareSearchRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" TestMode="false" MaskPassengerData="false" AllowDifferentBeginAndEndAirports="false">........ ......


I would really appreciate an early reply. I am new to xslt and the part to transform from one xml to anoth xml is confusing me the most. Can you also recommend a good xslt book for that thing.

Thanks,

--Abbi

abbi
05-18-2010, 06:16 PM
I think I posted the wrong stylesheet code. The correct one is:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" >


<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:call-template name="WrapWithSoap">
<xsl:with-param name="METHOD">
<xsl:copy-of select="./*" />
</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template name="WrapWithSoap">
<xsl:param name="METHOD"/>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<xsl:copy-of select="$METHOD"/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</xsl:template>
</xsl:stylesheet>