0

I need to check the shrui value for the each available room in a specific hotel if it is equal with previous room noofroom value has to be 2. other wise value just 1 . I have tried that It didn't work. Below is My Code. Can any one please help me on this.

  <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="preceding-sibling::hm:HotelRoom[1]/@SHRUI=@SHRUI">
                    <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>

My XML

<AvailableRoom>
        <HotelOccupancy>
          <RoomCount>1</RoomCount>
          <Occupancy>
            <AdultCount>1</AdultCount>
            <ChildCount>0</ChildCount>
          </Occupancy>
        </HotelOccupancy>
        <HotelRoom SHRUI="H6xFv7ejhSWcGuc+BCBYmg==" availCount="2" onRequest="N">
          <Board type="SIMPLE" code="FB-E10" shortname="FB">FULL BOARD</Board>
          <RoomType type="SIMPLE" code="SGL-E10" characteristic="ST">SINGLE STANDARD</RoomType>
          <Price>
            <Amount>269.580</Amount>
          </Price>
        </HotelRoom>
      </AvailableRoom>
      <AvailableRoom>
        <HotelOccupancy>
          <RoomCount>1</RoomCount>
          <Occupancy>
            <AdultCount>1</AdultCount>
            <ChildCount>0</ChildCount>
          </Occupancy>
        </HotelOccupancy>
        <HotelRoom SHRUI="H6xFv7ejhSWcGuc+BCBYmg==" availCount="2" onRequest="N">
          <Board type="SIMPLE" code="FB-E10" shortname="FB">FULL BOARD</Board>
          <RoomType type="SIMPLE" code="SGL-E10" characteristic="ST">SINGLE STANDARD</RoomType>
          <Price>
            <Amount>269.580</Amount>
          </Price>
        </HotelRoom>
      </AvailableRoom>
4

1 回答 1

0

In your sample the HotelRoom elements are not siblings, I think you want to change

<xsl:when test="preceding-sibling::hm:HotelRoom[1]/@SHRUI=@SHRUI">

to

<xsl:when test="parent::hm:AvailableRoom/preceding-sibling::hm:AvailableRoom[1]/hm:HotelRoom/@SHRUI=@SHRUI">

as the HotelRoom elements are children of AvailableRoom elements which are siblings.

于 2013-07-29T11:34:51.490 回答