1

如果条件为真,我需要将当前节点值从前一个节点值增加一。我在下面附上了我的 XSLT 和 XML。如果董事会和房间类型相同,我想将 noofroom 的值从以前的 noofroom 值增加一。否则 noofroom 应该是一个。目前我手动将其设置为 2。任何人都可以帮我解决这个问题。我的 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>

我的 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>
4

0 回答 0