Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7549861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:03:51+00:00 2026-05-30T10:03:51+00:00

i am facing a problem while apply xsl on xml. the xml is having

  • 0

i am facing a problem while apply xsl on xml. the xml is having same name “item” for hotel, roomresponse and dailyrate. how do i resolve this issue?

here is the xml request,

<availableHotels enc:itemType="ns1:hotel" enc:arraySize="7" xsi:type="ns1:hotelArray">
    <item xsi:type="ns1:hotel">
        <processId xsi:type="xsd:string">HZ-51743575</processId>
        <hotelCode xsi:type="xsd:string">INHEYT</hotelCode>
        <availabilityStatus xsi:type="xsd:string">InstantConfirmation</availabilityStatus>
        <totalPrice xsi:type="xsd:float">275</totalPrice>
        <totalTax xsi:type="xsd:float">0</totalTax>
        <currency xsi:type="xsd:string">USD</currency>
        <boardType xsi:type="xsd:string">Room and Breakfast (Buffet)</boardType>
        <rooms enc:itemType="ns1:roomResponse" enc:arraySize="1" xsi:type="ns1:roomResponseArray">
            <item xsi:type="ns1:roomResponse">
                <roomCategory xsi:type="xsd:string">Standard Twin Room</roomCategory>
                <paxes enc:itemType="ns1:pax" enc:arraySize="2" xsi:type="ns1:paxesArray">
                    <item xsi:type="ns1:pax">
                        <paxType xsi:type="xsd:string">Adult</paxType>
                        <age xsi:type="xsd:integer">30</age>
                    </item>
                    <item xsi:type="ns1:pax">
                        <paxType xsi:type="xsd:string">Child</paxType>
                        <age xsi:type="xsd:integer">5</age>
                    </item>
                </paxes>
                <totalRoomRate xsi:type="xsd:float">275</totalRoomRate>
                <ratesPerNight enc:itemType="ns1:dailyRate" enc:arraySize="2" xsi:type="ns1:dailyRateArray">
                    <item xsi:type="ns1:dailyRate">
                        <date xsi:type="xsd:date">2012-02-25</date>
                        <amount xsi:type="xsd:float">138</amount>
                    </item>
                    <item xsi:type="ns1:dailyRate">
                        <date xsi:type="xsd:date">2012-02-26</date>
                        <amount xsi:type="xsd:float">137</amount>
                    </item>
                </ratesPerNight>
            </item>
        </rooms>
    </item>
</availableHotels>

xsl i have used,

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <Property>
            <xsl:apply-templates select="//availableHotels/item"/>1
        </Property>
    </xsl:template>
    <xsl:template match="item">
        <Rooms>
            <Room>
                <Rate>
                    <Nights>
                        <xsl:apply-templates select="ratesPerNight"/>
                    </Nights>
                </Rate>
            </Room>
        </Rooms>
    </xsl:template>
    <xsl:template match="ratesPerNight">
        <Night>
            ????????
        </Night>
    </xsl:template>
</xsl:stylesheet>

Expected o/p:

<Property>
    <Rooms>
        <Room>
            <Rate>
                <Nights>
                    <Night Amount="6825.00" BookedDate="2012-02-25"/>
                                    <Night Amount="6825.00" BookedDate="2012-02-26"/>
                </Nights>
            </Rate>
        </Room>
    </Rooms>
</Property>

please help me to find out the solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:03:52+00:00Added an answer on May 30, 2026 at 10:03 am

    It is possible to specify attributes on templates:

    <xsl:template match="item[@xsi:type='ns1:dailyRate']">
    </xsl:template>
    

    This will only match those items… hope it helps

    Actually, leave out the ‘xsi:’
    Here is more code to get you started

        <xsl:output method="xml" encoding="utf-8" indent="no"/>
          <xsl:template match="/availableHotels">
            <Property>
                <xsl:apply-templates select="item/rooms"/>
            </Property>
        </xsl:template>
    
        <xsl:template match="rooms">
           <Room>
                <xsl:apply-templates select="item"/>
           </Room>
        <xsl:value-of select="@type"/>
        </xsl:template> 
    
        <xsl:template match="item[@type='ns1:roomResponse']">
         <xsl:value-of select="totalRoomRate"/>
         <xsl:value-of select="@type"/>
        </xsl:template>
    
    
    
        <xsl:template match="item">
         <xsl:value-of select="@type"/>
        </xsl:template>                                             
    
        <xsl:template match="*">
         <xsl:value-of select="name()"/>
        </xsl:template> 
    

    The last template is very useful to capture the ones you have missed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing a problem while creating a static cursor in DB2. This is
I am facing this problem while installing extensions, themes basically anything from magento connect.
I am facing one problem while writing one xslt: xml: <students> <studentDetails tag=to id=1
Hi I am facing this problem while building a source using ant Problem: failed
I am facing this problem while trying to run my java file by writing
I am facing the problem the problem while parsing the XML. Its cosuming 47%
I'm facing a particular problem while parsing xml so the parser works fine until
I am facing the problem while inserting data this way. How to insert data
I'm facing a problem while unit testing my forms. The problem is that data
I'm facing a problem with IE6. I took the toggle function from this website

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.