1

I have not much experience in xsl with namespace and i am using xsl for transforming the xml.

Here is the xml input,

<GetAvailability>
    <RequestSection>
        <Hotel>
            <StayDateRange Start="25/02/2012" End="27/02/2012"/>
            <HotelSearchCriteria>
                <HotelRef HotelCityName="MUMBAI" HotelCityCode="666" Currency="USD" Nationality="US"/>
                <Rooms>
                <Room Type="Single" ChildCount="1" AdultsCount="1" ExtraBed="0" RateBasis="-1">
                    <Ages>
                        <Age>5</Age>
                    </Ages>
                </Room>
            </Rooms>

            </HotelSearchCriteria>
        </Hotel>
    </RequestSection>
</GetAvailability>

I am expecting the output as,

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:b2bHotelSOAP" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
    <soap:Header/>
    <soap:Body>
        <urn:getAvailableHotel soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
            <destinationId xsi:type="xsd:string">666</destinationId>
            <checkIn xsi:type="xsd:date">2011-09-01</checkIn>
            <checkOut xsi:type="xsd:date">2011-09-03</checkOut>
            <currency xsi:type="xsd:string">USD</currency>
            <clientNationality xsi:type="xsd:string">US</clientNationality>
            <onRequest xsi:type="xsd:boolean">True</onRequest>
                        <rooms xsi:type="urn:roomArray" soapenc:arrayType="urn:paxesArray">
            <paxes>
                <pax>
                    <paxType>Adult</paxType>
                </pax>
            </paxes>
                       </rooms>

        </urn:getAvailableHotel>
    </soap:Body>
</soap:Envelope>

EDIT : here is the xsl i have tried,

 <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:template name="start" match="/">
        <xsl:if test="//HotelSearchCriteria/HotelRef/@HotelCityName != ''">
            <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:b2bHotelSOAP" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
                <soap:Header/>
                <soap:Body>
                    <urn:getAvailableHotel soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
                        <apiKey xsi:type="xsd:string">
                            <xsl:value-of select="//ApiKey"/>
                        </apiKey>
                        <destinationId xsi:type="xsd:string">
                            <xsl:value-of select="//HotelRef/@HotelCityCode"/>
                        </destinationId>
                        <checkIn xsi:type="xsd:date">
                            <xsl:value-of select="//StayDateRange/@Start"/>
                        </checkIn>
                        <checkOut xsi:type="xsd:date">
                            <xsl:value-of select="//StayDateRange/@End"/>
                        </checkOut>
                        <currency xsi:type="xsd:string">
                            <xsl:value-of select="//Currency"/>
                        </currency>
                        <clientNationality xsi:type="xsd:string">
                            <xsl:value-of select="//Nationality"/>
                        </clientNationality>
                        <onRequest xsi:type="xsd:boolean">
                            <xsl:value-of select="//HotelAdvanacedSearchCriteria/Available"/>
                        </onRequest>
                        <rooms xsi:type="urn:roomArray" soapenc:arrayType="urn:paxesArray">
                            <xsl:apply-templates select="//HotelSearchCriteria/Rooms/Room" mode="search"/>

                        </rooms>
                        <filters xsi:type="urn:filterArray" soapenc:arrayType="urn:filter"/>
                    </urn:getAvailableHotel>
                </soap:Body>
            </soap:Envelope>
        </xsl:if>
    </xsl:template>
    <xsl:template match="Room">
        <paxes>
            <xsl:attribute name="xsi:type">urn:paxesArray</xsl:attribute>

        </paxes>
    </xsl:template>

</xsl:stylesheet>

please suggest me the solution for this query.

4
  • 1
    What have you tried? Commented Feb 18, 2012 at 8:59
  • Edited with the xsl i have tried! Commented Feb 18, 2012 at 9:09
  • What is wrong? It isn't transforming at all? or are there certain tags that are wrong? Commented Feb 18, 2012 at 9:22
  • @Sujit Now we're talking! I think my answer should fix your problem. Commented Feb 18, 2012 at 9:46

1 Answer 1

1

It seems like your actual problem is in the Room template ...

<xsl:template match="Room">
    <paxes>
        <xsl:attribute name="xsi:type">urn:paxesArray</xsl:attribute>
    </paxes>
</xsl:template>

... because your Xsl will complain it doesn't recognize the xsi namespace.

To fix this, you have to add the namespace to all the templates where you intend to use it - or add it at the top level inside <xsl:stylesheet />.

<xsl:template match="Room" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <paxes>
        <xsl:attribute name="xsi:type">urn:paxesArray</xsl:attribute>
    </paxes>
</xsl:template>

or - if you want to keep the way you added your attributes in your start template

<xsl:template match="Room" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <paxes xsi:type="urn:paxesArray">
        <xsl:apply-templates />
    </paxes>
</xsl:template>

And you have to change applying your Room template inside rooms to just <apply-templates />:

<rooms xsi:type="urn:roomArray" soapenc:arrayType="urn:paxesArray">
    <xsl:apply-templates />
</rooms>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.