如何计算不同的节点?

时间:2009-08-11 14:06:27

标签: xslt sorting

的test.xml

<ServiceHotel>
  <AvailableRoom>
    <HotelOccupancy>
      <RoomCount>1</RoomCount>
      <Occupancy>
        <AdultCount>2</AdultCount>
        <ChildCount>1</ChildCount>
      </Occupancy>
    </HotelOccupancy>
    <HotelRoom>
      <Board>AFULL BOARD</Board>
      <RoomType>DOUBLE / TWIN STANDARD</RoomType>
      <Price>
        <Amount>33.195</Amount>
      </Price>
    </HotelRoom>
  </AvailableRoom>
  <AvailableRoom>
    <HotelOccupancy>
      <RoomCount>1</RoomCount>
      <Occupancy>
        <AdultCount>3</AdultCount>
        <ChildCount>0</ChildCount>
      </Occupancy>
    </HotelOccupancy>
    <HotelRoom>
      <Board>AFULL BOARD</Board>
      <RoomType>DOUBLE / TWIN STANDARD</RoomType>
      <Price>
        <Amount>23.002</Amount>
      </Price>
    </HotelRoom>
  </AvailableRoom>
  <AvailableRoom>
    <HotelOccupancy>
      <RoomCount>1</RoomCount>
      <Occupancy>
        <AdultCount>1</AdultCount>
        <ChildCount>0</ChildCount>
      </Occupancy>
    </HotelOccupancy>
    <HotelRoom>
      <Board>AFULL BOARD</Board>
      <RoomType>SINGLE STANDARD</RoomType>
      <Price>
        <Amount>16.205</Amount>
      </Price>
    </HotelRoom>
  </AvailableRoom>
  <AvailableRoom>
    <HotelOccupancy>
      <RoomCount>1</RoomCount>
      <Occupancy>
        <AdultCount>1</AdultCount>
        <ChildCount>0</ChildCount>
      </Occupancy>
    </HotelOccupancy>
    <HotelRoom>
      <Board>AFULL BOARD</Board>
      <RoomType>SINGLE STANDARDds</RoomType>
      <Price>
        <Amount>156.205</Amount>
      </Price>
    </HotelRoom>
  </AvailableRoom>
  <AvailableRoom>
    <HotelOccupancy>
      <RoomCount>1</RoomCount>
      <Occupancy>
        <AdultCount>1</AdultCount>
        <ChildCount>0</ChildCount>
      </Occupancy>
    </HotelOccupancy>
    <HotelRoom>
      <Board>AFULL BOARD</Board>
      <RoomType>SINGLE STANDARDs</RoomType>
      <Price>
        <Amount>3.205</Amount>
      </Price>
    </HotelRoom>
  </AvailableRoom>
  <AvailableRoom>
    <HotelOccupancy>
      <RoomCount>1</RoomCount>
      <Occupancy>
        <AdultCount>1</AdultCount>
        <ChildCount>0</ChildCount>
      </Occupancy>
    </HotelOccupancy>
    <HotelRoom>
      <Board>BED AND BREAKFAST</Board>
      <RoomType>SINGLE STANDARD</RoomType>
      <Price>
        <Amount>13.066</Amount>
      </Price>
    </HotelRoom>
  </AvailableRoom>
  <AvailableRoom>
    <HotelOccupancy>
      <RoomCount>1</RoomCount>
      <Occupancy>
        <AdultCount>1</AdultCount>
        <ChildCount>0</ChildCount>
      </Occupancy>
    </HotelOccupancy>
    <HotelRoom>
      <Board>HALF BOARD</Board>
      <RoomType>SINGLE STANDARD</RoomType>
      <Price>
        <Amount>13.590</Amount>
      </Price>
    </HotelRoom>
  </AvailableRoom>
  <AvailableRoom>
    <HotelOccupancy>
      <RoomCount>1</RoomCount>
      <Occupancy>
        <AdultCount>1</AdultCount>
        <ChildCount>0</ChildCount>
      </Occupancy>
    </HotelOccupancy>
    <HotelRoom>
      <Board>FULL BOARD</Board>
      <RoomType>SINGLE STANDARD</RoomType>
      <Price>
        <Amount>16.205</Amount>
      </Price>
    </HotelRoom>
  </AvailableRoom>
  <AvailableRoom>
    <HotelOccupancy>
      <RoomCount>1</RoomCount>
      <ChildCount>0</ChildCount>
      <Occupancy>
        <AdultCount>2</AdultCount>
        <ChildCount>1</ChildCount>
      </Occupancy>
    </HotelOccupancy>
    <HotelRoom>
      <Board>BED AND BREAKFAST</Board>
      <RoomType>DOUBLE / TWIN STANDARD</RoomType>
      <Price>
        <Amount>16.725</Amount>
      </Price>
    </HotelRoom>
  </AvailableRoom>
  <AvailableRoom>
    <HotelOccupancy>
      <RoomCount>1</RoomCount>
      <Occupancy>
        <AdultCount>3</AdultCount>
        <ChildCount>0</ChildCount>
      </Occupancy>
    </HotelOccupancy>
    <HotelRoom>
      <Board>BED AND BREAKFAST</Board>
      <RoomType>DOUBLE / TWIN STANDARD</RoomType>
      <Price>
        <Amount>23.414</Amount>
      </Price>
    </HotelRoom>
  </AvailableRoom>
  <AvailableRoom>
    <HotelOccupancy>
      <RoomCount>1</RoomCount>
      <Occupancy>
        <AdultCount>2</AdultCount>
        <ChildCount>1</ChildCount>
      </Occupancy>
    </HotelOccupancy>
    <HotelRoom>
      <Board>HALF BOARD</Board>
      <RoomType>DOUBLE / TWIN STANDARD</RoomType>
      <Price>
        <Amount>17.772</Amount>
      </Price>
    </HotelRoom>
  </AvailableRoom>
  <AvailableRoom>
    <HotelOccupancy>
      <RoomCount>1</RoomCount>
      <Occupancy>
        <AdultCount>3</AdultCount>
        <ChildCount>0</ChildCount>
      </Occupancy>
    </HotelOccupancy>
    <HotelRoom>
      <Board>HALF BOARD</Board>
      <RoomType>DOUBLE / TWIN STANDARD</RoomType>
      <Price>
        <Amount>24.879</Amount>
      </Price>
    </HotelRoom>
  </AvailableRoom>
  <AvailableRoom>
    <HotelOccupancy>
      <RoomCount>1</RoomCount>
      <Occupancy>
        <AdultCount>3</AdultCount>
        <ChildCount>0</ChildCount>
      </Occupancy>
    </HotelOccupancy>
    <HotelRoom>
      <Board>FULL BOARD</Board>
      <RoomType>DOUBLE / TWIN STANDARD</RoomType>
      <Price>
        <Amount>23.002</Amount>
      </Price>
    </HotelRoom>
  </AvailableRoom>
  <AvailableRoom>
    <HotelOccupancy>
      <RoomCount>1</RoomCount>
      <Occupancy>
        <AdultCount>1</AdultCount>
        <ChildCount>0</ChildCount>
      </Occupancy>
    </HotelOccupancy>
    <HotelRoom>
      <Board>ROOM ONLY</Board>
      <RoomType>SINGLE STANDARD</RoomType>
      <Price>
        <Amount>33.290</Amount>
      </Price>
    </HotelRoom>
  </AvailableRoom>
  <AvailableRoom>
    <HotelOccupancy>
      <RoomCount>1</RoomCount>
      <Occupancy>
        <AdultCount>2</AdultCount>
        <ChildCount>1</ChildCount>
      </Occupancy>
    </HotelOccupancy>
    <HotelRoom>
      <Board>FULL BOARD</Board>
      <RoomType>DOUBLE / TWIN STANDARD</RoomType>
      <Price>
        <Amount>34.195</Amount>
      </Price>
    </HotelRoom>
  </AvailableRoom>
  <AvailableRoom>
    <HotelOccupancy>
      <RoomCount>1</RoomCount>
      <Occupancy>
        <AdultCount>3</AdultCount>
        <ChildCount>0</ChildCount>
      </Occupancy>
    </HotelOccupancy>
    <HotelRoom>
      <Board>ROOM ONLY</Board>
      <RoomType>DOUBLE / TWIN STANDARD SEA VIEW</RoomType>
      <Price>
        <Amount>34.195</Amount>
      </Price>
    </HotelRoom>
  </AvailableRoom>
</ServiceHotel>

test.xsl

<xsl:stylesheet 
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
  <xsl:output method="html" indent="yes" />

  <xsl:key name="by-board" match="AvailableRoom/HotelRoom" use="Board" />
  <xsl:key name="Adult" match="Occupancy" use="AdultCount" />

  <xsl:template match="/">
    <xsl:apply-templates select="ServiceHotel" />
  </xsl:template>

  <xsl:variable name="AdCount">
    <xsl:value-of select="count(/ServiceHotel/AvailableRoom/HotelOccupancy/Occupancy [generate-id(.) = generate-id(key('Adult', AdultCount)[1])])" />
  </xsl:variable>

  <xsl:template match="ServiceHotel">
    <br></br>
    <xsl:for-each select="
      AvailableRoom/HotelRoom[
        generate-id() = generate-id(key('by-board', Board)[1]) 
        and 
        count(key('by-board', Board)) &gt;= $AdCount]
    ">
      <xsl:sort select="
        sum(
          key('by-board', Board)[position() 
          &lt;
          ($AdCount +1)]/Price/Amount
        )
      " />
      <xsl:apply-templates select="." mode="group" />
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="AvailableRoom/HotelRoom" mode="group">
    <xsl:apply-templates select="key('by-board', Board)" />
    <br></br>
    <xsl:value-of select="format-number(sum(key('by-board', Board)[position() &lt; ($AdCount +1) ]/Price/Amount), '#.000')" />
    <br></br>
  </xsl:template>

  <xsl:template match="AvailableRoom/HotelRoom">
    <xsl:choose>
      <xsl:when test="position() &lt; ($AdCount +1)">
        <br></br>
        <xsl:value-of select="concat(RoomType, ', ', Board)" />
        <br></br>
        <xsl:value-of select="format-number(Price/Amount, '#.000')" />
      </xsl:when>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>

输出

SINGLE STANDARD, BED AND BREAKFAST
13.066 DOUBLE / TWIN STANDARD, BED AND BREAKFAST
16.725 DOUBLE / TWIN STANDARD, BED AND BREAKFAST
23.414 Total : 53.205

SINGLE STANDARD, HALF BOARD
13.590 DOUBLE / TWIN STANDARD, HALF BOARD
17.772 DOUBLE / TWIN STANDARD, HALF BOARD
24.879 Total : 56.241

**DOUBLE / TWIN STANDARD, AFULL BOARD         ''' ******
33.195 DOUBLE / TWIN STANDARD, AFULL BOARD           ''' ******
23.002 SINGLE STANDARD, AFULL BOARD                  ....******
16.205** Total : 72.402

SINGLE STANDARD, FULL BOARD
16.205 DOUBLE / TWIN STANDARD, FULL BOARD
23.002 DOUBLE / TWIN STANDARD, FULL BOARD
34.195 Total : 73.402

我如何用asc命令对电路板进行排序?

0 个答案:

没有答案