1

I need to increase current node value by one from previous node value if the condition is true. I have attached My XSLT and XML below. if board and room type are same I want increase value of noofroom by one from previous noofroom value. otherwise noofroom should be one.currently I set it to 2 manually. can any one please help me on this. My XML...

 <AvailableRoom>
                <HotelOccupancy>
                  <RoomCount>1</RoomCount>
                  <Occupancy>
                    <AdultCount>1</AdultCount>
                    <ChildCount>0</ChildCount>
                  </Occupancy>
                </HotelOccupancy>
                <HotelRoom SHRUI="DVB8XS0PRiyGagcJUhDETw==" availCount="2" onRequest="N">
                  <Board type="SIMPLE" code="RO-E10" shortname="RO">ROOM ONLY</Board>
                  <RoomType type="SIMPLE" code="SGL-E10" characteristic="DX">SINGLE DELUXE</RoomType>
                  <Price>
                    <Amount>178.020</Amount>
                  </Price>
                </HotelRoom>
              </AvailableRoom>
              <AvailableRoom>
                <HotelOccupancy>
                  <RoomCount>1</RoomCount>
                  <Occupancy>
                    <AdultCount>1</AdultCount>
                    <ChildCount>1</ChildCount>
                  </Occupancy>
                </HotelOccupancy>
                <HotelRoom SHRUI="yrfO/b/aFGqxZ9ks6Lu2Tg==" availCount="2" onRequest="N">
                  <Board type="SIMPLE" code="RO-E10" shortname="RO">ROOM ONLY</Board>
                  <RoomType type="SIMPLE" code="DBL-E10" characteristic="DX">DOUBLE DELUXE</RoomType>
                  <Price>
                    <Amount>186.480</Amount>
                  </Price>
                </HotelRoom>
              </AvailableRoom>

My XSLT.

<xsl:for-each select="hm:AvailableRoom ">
            <availableroom>           
                <hotelcode>
                  <xsl:value-of select="preceding-sibling::hm:HotelInfo/hm:Code"/>
                </hotelcode>             
              <xsl:for-each select="hm:HotelOccupancy ">
                <roomcount>
                  <xsl:value-of select="hm:RoomCount"/>
                </roomcount>
                <xsl:for-each select="hm:Occupancy ">
                  <guests>
                    <xsl:value-of select="sum((hm:AdultCount | hm:ChildCount)[number(.) = .])"/>
                  </guests>
                  <adults>
                    <xsl:value-of select="hm:AdultCount"/>
                  </adults>
                  <children>
                    <xsl:value-of select="hm:ChildCount"/>
                  </children>
                </xsl:for-each>
              </xsl:for-each>
              <xsl:for-each select="hm:HotelRoom ">
                <shrui>
                  <xsl:value-of select="@SHRUI"/>
                </shrui>
                <xsl:choose>
                  <xsl:when test="parent::hm:AvailableRoom/preceding-sibling::hm:AvailableRoom[1]/hm:HotelRoom/hm:RoomType=hm:RoomType and parent::hm:AvailableRoom/preceding-sibling::hm:AvailableRoom[1]/hm:HotelRoom/hm:Board=hm:Board">
                    <noofroom>2</noofroom>                    
                  </xsl:when>
                  <xsl:otherwise>
                    <noofroom>1</noofroom>
                  </xsl:otherwise>
                </xsl:choose>
                <board>
                  <xsl:value-of select="hm:Board"/>
                </board>
                <roomtype>
                  <xsl:value-of select="hm:RoomType"/>
                </roomtype>
                <roomcode>
                  <xsl:value-of select="hm:RoomType/@code"/>
                </roomcode>
                <boardcode>
                  <xsl:value-of select="hm:Board/@code"/>
                </boardcode>
                <xsl:for-each select="hm:Price ">
                  <amount>
                    <xsl:value-of select="hm:Amount"/>
                  </amount>
                </xsl:for-each>
              </xsl:for-each>
            </availableroom>
          </xsl:for-each>
Sirojan Gnanaretnam
  • 601
  • 1
  • 22
  • 45
  • So what's your question? Can you show us your desired output? – JLRishe Jul 30 '13 at 07:04
  • Is the data sorted in anyway? Will the "board" and "room" elements with the same type always be consecutive in the document, or could they be anywhere? – Tim C Jul 30 '13 at 07:42
  • possible duplicate of [Counter inside xsl:for-each loop](http://stackoverflow.com/questions/93511/counter-inside-xslfor-each-loop) – Paul Sweatte May 25 '15 at 15:28

0 Answers0