0

我的 xslt 仅适用于 XMl 中的第一条记录,但不适用于其他记录。我不确定如何通过 xslt 填充其他记录。我确信它与酒店订单有关 = 但我对 XMl 的东西不熟悉所以请帮忙。

请帮我

xml的代码如下:

<?xml version="1.0" encoding="ISO-8859-1"?>
<DestinationResults size="1">
  <Destination name="Paris, FRA" order="1">
    <HotelAvailabilityListResults size="10">
      <Hotel order="1">
        <hotelId>188139</hotelId>
        <name>
          <![CDATA[ Hotel Magenta Paris ]]>
        </name>
        <address1>38 Boulevard De Magenta</address1>
        <address2/>
        <address3/>
        <city>Paris</city>
        <stateProvince/>
        <country>FR</country>
        <postalCode>75010</postalCode>
        <latitude>48.87203</latitude>
        <longitude>2.35995</longitude>
        <tripAdvisorRating>4.0</tripAdvisorRating>
        <fromDate>10/11/2013</fromDate>
        <toDate>10/12/2013</toDate>
        <shortDescription>
          <![CDATA[&lt;p&gt;&lt;b&gt;Property Location&lt;/b&gt; &lt;br /&gt;With a stay at Hotel Magenta Paris in Paris (Gare du Nord - Gare de L&apos;Est), you&apos;ll be minutes from Porte Saint-Martin and close to Louvre Museum. This]]>
        </shortDescription>
        <thumbNailUrl>
http://origin-images.ian.com/hotels/1000000/890000/889000/888903/888903_22_t.jpg
        </thumbNailUrl>
        <propertyRating>3.0</propertyRating>
        <referenceProximityDistance>-1.0</referenceProximityDistance>
        <referenceProximityUnit/>
        <HotelProperty>
          <promoDescription>Stay 1 nights and save 10% off your stay!</promoDescription>
          <ValueAdds>
            <valueAdd id="2048">Free Wireless Internet</valueAdd>
          </ValueAdds>
          <PromoRateInfo>
            <displayCurrencyCode>USD</displayCurrencyCode>
            <DisplayNightlyRates size="1">
              <displayNightlyRate>152.02</displayNightlyRate>
            </DisplayNightlyRates>
            <displayRoomRate>168.68</displayRoomRate>
            <chargeableRoomRateTotal>168.68</chargeableRoomRateTotal>
            <chargeableRoomRateTaxesAndFees>16.66</chargeableRoomRateTaxesAndFees>
            <taxesOnly>16.66</taxesOnly>
            <salesTax>0</salesTax>
            <hotelOccupancyTax>0</hotelOccupancyTax>
            <nativeCurrencyCode>USD</nativeCurrencyCode>
            <NativeNightlyRates size="1">
              <nativeNightlyRate>152.02</nativeNightlyRate>
            </NativeNightlyRates>
            <nativeRoomRate>168.68</nativeRoomRate>
            <rateFrequency>B</rateFrequency>
          </PromoRateInfo>
          <RateInfo>
            <displayCurrencyCode>USD</displayCurrencyCode>
            <DisplayNightlyRates size="1">
              <displayNightlyRate>168.91</displayNightlyRate>
            </DisplayNightlyRates>
            <displayRoomRate>185.57</displayRoomRate>
            <chargeableRoomRateTotal>185.57</chargeableRoomRateTotal>
            <chargeableRoomRateTaxesAndFees>16.66</chargeableRoomRateTaxesAndFees>
            <taxesOnly>16.66</taxesOnly>
            <salesTax>0</salesTax>
            <hotelOccupancyTax>0</hotelOccupancyTax>
            <nativeCurrencyCode>USD</nativeCurrencyCode>
            <NativeNightlyRates size="1">
              <nativeNightlyRate>168.91</nativeNightlyRate>
            </NativeNightlyRates>
            <nativeRoomRate>185.57</nativeRoomRate>
            <rateFrequency>B</rateFrequency>
          </RateInfo>
        </HotelProperty>
        <hotelUrl>
http://booking.rated-hotels.co.uk/index.jsp?pageName=hotAvail&cid=409870&hotelID=188139&mode=2&numberOfRooms=1&room-0-adult-total=2&room-0-child-total=0&arrivalMonth=9&arrivalDay=11&departureMonth=9&departureDay=12&showInfo=true&locale=en_US&currencyCode=USD&mcicid=409870.HOTEL.XML.85419
        </hotelUrl>
      </Hotel>

    </HotelAvailabilityListResults>
  </Destination>
</DestinationResults>

我的 Xslt 如下:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
  <body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">

    <xsl:for-each select="DestinationResults">
    <xsl:for-each select="Destination">
    <xsl:for-each select="HotelAvailabilityListResults">
    <xsl:for-each select="Hotel">

      <div style="background-color:teal;color:white;padding:4px">
        <span style="font-weight:bold"><xsl:value-of select="name"/></span>
        - <xsl:value-of select="city"/>
      </div>
      <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
        <p><xsl:value-of select="shortDescription"/>.
        <span style="font-style:italic">
          <xsl:value-of select="address1"/> 
        </span>.</p>
      </div>
    </xsl:for-each>
    </xsl:for-each>
    </xsl:for-each>
    </xsl:for-each>

  </body>
</html>
4

1 回答 1

0

我刚刚在http://xslttest.appspot.com/ 上通过在线测试器测试了 xml 和 xsl到 %26 (对于 url,请记住对任何特殊字符进行 url 编码,对于 xml 字段,请记住对 xml 编码)

一个 2 条目 xml 文件在这里

一个修改过的 xsl 文件在这里

xsl 转换为我返回了两个条目,但您仍需要更正一些值的格式以确保其正确显示。

于 2013-11-08T14:23:42.163 回答