1

我想使用 XSLT 转换肥皂 xml 响应。下面是我的代码。我需要将 paginationdata 作为根元素。我想遍历下面示例中的每个 Servicehotel 标签。谁能帮我做到这一点。

XML 响应


<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <ns1:getHotelValuedAvail xsi:type="xsd:string" xmlns:ns1="http://axis.frontend.hydra.hotelbeds.com">
      <HotelValuedAvailRS xmlns="http://www.hotelbeds.com/schemas/2005/06/messages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.hotelbeds.com/schemas/2005/06/messages HotelValuedAvailRS.xsd" timeToExpiration="1799992" totalItems="15" echoToken="DummyEchoToken">
        <AuditData>
          <ProcessTime>223</ProcessTime>
          <Timestamp>2013-07-04 09:27:02.390</Timestamp>
          <RequestHost>222.165.187.74:74</RequestHost>
          <ServerName>LIVE</ServerName>
          <ServerId>50</ServerId>
          <SchemaRelease>2005/06</SchemaRelease>
          <HydraCoreRelease>2.0.201303260936</HydraCoreRelease>
          <HydraEnumerationsRelease>1.0.201303260936</HydraEnumerationsRelease>
          <MerlinRelease>N/A</MerlinRelease>
        </AuditData>
        <PaginationData currentPage="1" totalPages="1" />
        <ServiceHotel xsi:type="ServiceHotel" availToken="KP3gWAJ1ddEDTyrlCaSV1A99">
          <ContractList>
            <Contract>
              <Name>GR-ALL</Name>
              <IncomingOffice code="246">
              </IncomingOffice>
              <Classification code="NOR">Online Price</Classification>
            </Contract>
          </ContractList>
          <DateFrom date="20130709" />
          <DateTo date="20130718" />
          <Currency code="EUR">Euro</Currency>
          <HotelInfo xsi:type="ProductHotel">
            <Code>68681</Code>
            <Name>Palm Village</Name>
            <ImageList>
              <Image>
                <Type>jpg</Type>
                <Order>1</Order>
                <VisualizationOrder>1</VisualizationOrder>
                <Url>http://www.hotelbeds.com/giata/small/06/068681/068681a_hb_a_003.jpg</Url>
              </Image>
              <Image>
                <Type>jpg</Type>
                <Order>2</Order>
                <VisualizationOrder>2</VisualizationOrder>
                <Url>http://www.hotelbeds.com/giata/small/06/068681/068681a_hb_a_004.jpg</Url>
              </Image>
            </ImageList>
            <Category type="SIMPLE" code="3EST" shortname="3*">3 STARS</Category>
            <Destination type="SIMPLE" code="CMB">
              <Name>Colombo</Name>
              <ZoneList>
                <Zone type="SIMPLE" code="4">Wattala</Zone>
              </ZoneList>
            </Destination>
            <ChildAge ageFrom="0" ageTo="11" />
            <Position latitude="7.03434100000000039898" longitude="79.86045000000000015916" />
          </HotelInfo>
          <AvailableRoom>
            <HotelOccupancy>
              <RoomCount>1</RoomCount>
              <Occupancy>
                <AdultCount>1</AdultCount>
                <ChildCount>1</ChildCount>
              </Occupancy>
            </HotelOccupancy>
            <HotelRoom SHRUI="U3FDY+qSddmfVcqIvPh/rA==" availCount="5" onRequest="N">
              <Board type="SIMPLE" code="BB-E10" shortname="BB">BED AND BREAKFAST</Board>
              <RoomType type="SIMPLE" code="DBL-E10" characteristic="ST">DOUBLE STANDARD</RoomType>
              <Price>
                <Amount>491.220</Amount>
              </Price>
            </HotelRoom>
          </AvailableRoom>
          <AvailableRoom>
            <HotelOccupancy>
              <RoomCount>1</RoomCount>
              <Occupancy>
                <AdultCount>1</AdultCount>
                <ChildCount>1</ChildCount>
              </Occupancy>
            </HotelOccupancy>
            <HotelRoom SHRUI="Z3ic82b/pyAApY8QglSI9w==" availCount="5" onRequest="N">
              <Board type="SIMPLE" code="HB-E10" shortname="HB">HALF BOARD</Board>
              <RoomType type="SIMPLE" code="DBL-E10" characteristic="ST">DOUBLE STANDARD</RoomType>
              <Price>
                <Amount>553.500</Amount>
              </Price>
            </HotelRoom>
          </AvailableRoom>
          <AvailableRoom>
            <HotelOccupancy>
              <RoomCount>1</RoomCount>
              <Occupancy>
                <AdultCount>1</AdultCount>
                <ChildCount>1</ChildCount>
              </Occupancy>
            </HotelOccupancy>
            <HotelRoom SHRUI="90N3gwP3wOa1+nt99/w6AQ==" availCount="5" onRequest="N">
              <Board type="SIMPLE" code="FB-E10" shortname="FB">FULL BOARD</Board>
              <RoomType type="SIMPLE" code="DBL-E10" characteristic="ST">DOUBLE STANDARD</RoomType>
              <Price>
                <Amount>615.960</Amount>
              </Price>
            </HotelRoom>
          </AvailableRoom>
        </ServiceHotel>
        <ServiceHotel xsi:type="ServiceHotel" availToken="KP3gWAJ1ddEDTyrlCaSV1A99">
          <ContractList>
            <Contract>
              <Name>GR-ALL</Name>
              <IncomingOffice code="246">
              </IncomingOffice>
              <Classification code="NOR">Online Price</Classification>
            </Contract>
          </ContractList>
          <DateFrom date="20130709" />
          <DateTo date="20130718" />
          <Currency code="EUR">Euro</Currency>
          <HotelInfo xsi:type="ProductHotel">
            <Code>156461</Code>
            <Name>Chandrika</Name>
            <ImageList>
              <Image>
                <Type>jpg</Type>
                <Order>1</Order>
                <VisualizationOrder>1</VisualizationOrder>
                <Url>http://www.hotelbeds.com/giata/small/15/156461/156461a_hb_a_008.jpg</Url>
              </Image>
              <Image>
                <Type>jpg</Type>
                <Order>2</Order>
                <VisualizationOrder>2</VisualizationOrder>
                <Url>http://www.hotelbeds.com/giata/small/15/156461/156461a_hb_w_001.jpg</Url>
              </Image>
            </ImageList>
            <Category type="SIMPLE" code="2EST" shortname="2*">2 STARS</Category>
            <Destination type="SIMPLE" code="CMB">
              <Name>Colombo</Name>
              <ZoneList>
                <Zone type="SIMPLE" code="1">Colombo City</Zone>
              </ZoneList>
            </Destination>
            <ChildAge ageFrom="0" ageTo="11" />
            <Position latitude="7.33518100000000039529" longitude="79.84394799999999747797" />
          </HotelInfo>
          <AvailableRoom>
            <HotelOccupancy>
              <RoomCount>1</RoomCount>
              <Occupancy>
                <AdultCount>1</AdultCount>
                <ChildCount>1</ChildCount>
              </Occupancy>
            </HotelOccupancy>
            <HotelRoom SHRUI="QgaQng5EoLHEKgW/dUSVsA==" availCount="2" onRequest="N">
              <Board type="SIMPLE" code="BB-E10" shortname="BB">BED AND BREAKFAST</Board>
              <RoomType type="SIMPLE" code="DBL-E10" characteristic="ST">DOUBLE STANDARD</RoomType>
              <Price>
                <Amount>553.680</Amount>
              </Price>
            </HotelRoom>
          </AvailableRoom>
          <AvailableRoom>
            <HotelOccupancy>
              <RoomCount>1</RoomCount>
              <Occupancy>
                <AdultCount>1</AdultCount>
                <ChildCount>1</ChildCount>
              </Occupancy>
            </HotelOccupancy>
            <HotelRoom SHRUI="vc4AawIhAC5qAmvUJfcRXA==" availCount="2" onRequest="N">
              <Board type="SIMPLE" code="HB-E10" shortname="HB">HALF BOARD</Board>
              <RoomType type="SIMPLE" code="DBL-E10" characteristic="ST">DOUBLE STANDARD</RoomType>
              <Price>
                <Amount>896.760</Amount>
              </Price>
            </HotelRoom>
          </AvailableRoom>
          <AvailableRoom>
            <HotelOccupancy>
              <RoomCount>1</RoomCount>
              <Occupancy>
                <AdultCount>1</AdultCount>
                <ChildCount>1</ChildCount>
              </Occupancy>
            </HotelOccupancy>
            <HotelRoom SHRUI="VjfoYN9kBHRObnr1RpQAvQ==" availCount="2" onRequest="N">
              <Board type="SIMPLE" code="FB-E10" shortname="FB">FULL BOARD</Board>
              <RoomType type="SIMPLE" code="DBL-E10" characteristic="ST">DOUBLE STANDARD</RoomType>
              <Price>
                <Amount>1099.620</Amount>
              </Price>
            </HotelRoom>
          </AvailableRoom>
        </ServiceHotel>
            </HotelValuedAvailRS>
    </ns1:getHotelValuedAvail>
  </soapenv:Body>
</soapenv:Envelope>

我的 XSLT

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
    <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Currency</th>

      </tr>
      <xsl:for-each select="//ServiceHotel">
      <tr>
        <td><xsl:value-of select="Currency"/></td>

      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
4

1 回答 1

1

您的源 XML 有一个默认名称空间,因此您必须在 XSLT 中使用这个名称空间。请试一试:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:hm="http://www.hotelbeds.com/schemas/2005/06/messages"
exclude-result-prefixes="hm">
<xsl:template match="/">
  <html>
  <body>
    <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Currency</th>

      </tr>
      <xsl:for-each select="//hm:ServiceHotel">
      <tr>
        <td><xsl:value-of select="hm:Currency"/></td>

      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
于 2013-07-05T07:36:05.437 回答