我是 xslt 的新手,正在尝试使用 xslt 从 xml 创建 html。
我不知道为什么,但我的 xslt 在只有一个元素时有效,但在多个时无效。
我尝试了各种方法,但正如我所说的那样,我是新手,不知道该怎么做。
这是我的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[<p><b>Property Location</b> <br />With a stay at Hotel Magenta Paris in Paris (Gare du Nord - Gare de L'Est), you'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¤cyCode=USD&mcicid=409870.HOTEL.XML.85419
</hotelUrl>
</Hotel>
<Hotel order="2">
<hotelId>188140</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[<p><b>Property Location</b> <br />With a stay at Hotel Magenta Paris in Paris (Gare du Nord - Gare de L'Est), you'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¤cyCode=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>
此 xslt 适用于上述 xml,但是当 xml 中有多个酒店订单(如下所示)时,xslt 不会产生任何结果。
<Hotel order="2">
<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[<p><b>Property Location</b> <br />With a stay at Hotel Magenta Paris in Paris (Gare du Nord - Gare de L'Est), you'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¤cyCode=USD&mcicid=409870.HOTEL.XML.85419
</hotelUrl>
</Hotel>
任何帮助深表感谢。
问候,杰