我有一个要求,需要使用xslt将xml格式化为html。我创建了超过五到六个xslt并且一切正常。但是现在,我解决了xslt无法识别第二个孩子的问题节点和它的元素。请看看,告诉我我错在哪里。
XML
<?xml version="1.0" encoding="utf-8"?>
<HotelSearchResults>
<Hotels>
<Hotel SupplierHotelID="1613" HotelId="77738" name="Charring Cross" areatransportation="Charing Cross can be easily located by the visitors and is only 2 kms. from the Ooty Bus Stand, 2 kms. from the Railway Station and about 90 kms. from the Coimbatore airport." restaurants="Restaurant." meetingfacility="Conference Hall facility Available." description="Charing Cross is a hotel in the picturesque hill station of Ooty offering a comfortable stay with a beautiful view of the surrounding Nilgiri hills. It is situated at a central place and is on the way to the Botanical Gardens. It is a comparatively new property vis-a-vis a lot of colonial bungalows in this very popular hill station and was only thrown open to the public in 1994. The hotel is on the Garden Road and is very close to both the Ooty Railway Station and the Bus Stand." overview="The hotel has some 90 lovely rooms that are categorized into Standard, Super Deluxe and Three- bedded rooms. The rooms are comfortable with basic amenities like television, hot and cold water, room service and a doctor on call. Also available is the laundry service and in case there is a need to mix business with pleasure, the conference room with fax machines et al come in handy. There is a friendly travel desk which organises travel tours and sightseeing packages." checkintime="12:00" checkouttime="12:00" LandmarkCategory="Area/Places; Area/Places; Airport &amp; Station; Area/Places; Area/Places; Area/Places; Area/Places; Area/Places; Area/Places; Area/Places; Area/Places; Airport &amp; Station; Area/Places; Area/Places; Area/Places; Area/Places; Area/Places; " Landmark="Art Galllery; Bus Stand; Coimbatore Airport; Dodabetta Peak; Glenmorgan; Hospital; Kalhatty Waterfalls; Kandal Cross; Lamb&#039;s Rock; Mini Garden; Pykara Falls; Railway Station; The Charring Cross; The Hindustan Photo Films; Lalith Kala Academy; Needle Point Rockview; Rose Garden; " theme="Business, " latitude="11.413287" longitude="76.708291" thumb="http://static.*****.co.in/*****/images/hotelimages/ezimages/ezthumbimg/77738_exterior_view.jpg;">
<StarRating Level="2"/>
<Address address="Garden Road" city="Ooty" state="Tamil Nadu" country="India" pincode=" " location="Garden Road, Hotel charing cross road" phone="0091 - 423 - 2441058"/>
<image path="http://static.*****.co.in/*****/images/hotelimages/ezimages/77738_exterior_view.jpg;"/>
<video/>
<HotelFacility>
<Facility name="Parking"/>
<Facility name="Room Service"/>
<Facility name="Restaurant"/>
<Facility name="Business Center"/>
<Facility name="Travel Desk"/>
<Facility name="Conference Hall"/>
</HotelFacility>
<HotelAmenity Restaurant="1" conference="1" fitness="0" travel="1" forex="0" shopping="0" banquet="0" games="0" Bar="0" Coffee_Shop="0" Room_Service="1" Internet_Access="0" Business_Centre="1" Swimming_Pool="0" Pets="0" Tennis_Court="0" Golf="0" Air_Conditioning="1" Parking="1" Wheel_Chair="0" Health_Club="0"/>
<HotelDistance DistancefromAirport="90 " DistancefromStation="2 " DistancefromBus="2 "/>
<RoomType name="Standard">
<Facility name="A/c Room"/>
<Facility name="Attached bath"/>
<Facility name="Hot &amp; Cold water"/>
<Facility name="Television"/>
<Facility name="Direct-dial phone"/>
<Facility name="Laundry"/>
</RoomType>
</Hotel>
<hoteldetail index="1" xmlns="http://www.*****.org/OTA/2003/05">
<hotelId id="1613" supplier="Desiya">77738</hotelId>
<hotelname>Charring Cross</hotelname>
<currency>INR</currency>
<isReprice>Y</isReprice>
<isProvisionalRequired>Y</isProvisionalRequired>
<ExtraInfo />
<roomDetails>
<room type="Standard Room" mealtype="Room Only" roomid="77738:0" price="782.1" allocation_status="A">
<sub-room index="0" price="711.0">
<offer />
<special_remarks />
<inclusion />
<Supplier_Currency>INR</Supplier_Currency>
<Supplier_Amount>790.0</Supplier_Amount>
<dayWise>
<day no="1">711.0</day>
</dayWise>
</sub-room>
</room>
<room type="Superior Room" mealtype="Room Only" roomid="77738:1" price="1277.1" allocation_status="A">
<sub-room index="1" price="1161.0">
<offer />
<special_remarks />
<inclusion />
<Supplier_Currency>INR</Supplier_Currency>
<Supplier_Amount>1290.0</Supplier_Amount>
<dayWise>
<day no="1">1161.0</day>
</dayWise>
</sub-room>
</room>
<room type="Executive Room" mealtype="Room Only" roomid="77738:2" price="1634.49" allocation_status="A">
<sub-room index="2" price="1485.9">
<offer />
<special_remarks />
<inclusion />
<Supplier_Currency>INR</Supplier_Currency>
<Supplier_Amount>1651.0</Supplier_Amount>
<dayWise>
<day no="1">1485.9</day>
</dayWise>
</sub-room>
</room>
</roomDetails>
</hoteldetail>
</Hotels>
<Hotels>
<Hotel SupplierHotelID="993" HotelId="77469" name="Khems" areatransportation="Hotel Khems sits pretty on Ettines Road and is about 110 kms. from Coimbatore airport, 1 km. from Ooty Railway station and a mere 1.5 kms. from the Bus Stand." restaurants="Multi-cusine Restaurant." description="Ooty stands out in its pristine beauty and tranquillity from all other hill stations in India. It served as the summer capital of the British Raj and still retains a large part of its colonial glory in its buildings and hotels. Apart from the blue hills of the Nilgiris, the thick greenery all around also makes Ooty very special indeed as do the Dodabetta peak, the Botanical gardens, the Lamb&#039;s Rock and the Pykara Lake. Hotel Khems is right in the middle of the town and close to all the major attractions, yet the lush greenery sets it apart and makes all its residents feel very close to nature." overview="Hotel Khems has some 45 well-furnished rooms equipped with all the modern amenities to make everyone&#039;s stay comfortable. A slew of modern facilities are inlcudes and they inlcude free, secure parking, express laundry service, money changers and forex, a helpful travel desk to meet travel and tour related queries, doctor on call, a multi-cuisine restaurant serving delicious food, a lovely picnic area out in the sun and an efficient room service that makes sure that all needs are well taken care of." checkintime="12:00" checkouttime="12:00" email="info@hotelkhems.com" website="www.hotelkhems.com" LandmarkCategory="Area/Places; Area/Places; Area/Places; Area/Places; Area/Places; Area/Places; Others; Area/Places; Area/Places; Area/Places; Area/Places; Area/Places; Area/Places; Area/Places; Area/Places; Area/Places; Area/Places; Area/Places; Area/Places; Others; Area/Places; Area/Places; Area/Places; Attractions; Area/Places; " Landmark="St. Joseph&#039;s Higher Secondary School, Ooty; Breeks Memorial School; Ooty Lake; Nilgiri Wildlife and Environment Association; Glenmorgan, Ooty; Ketti; Government Rose Garden, Ooty; Mariamman temple, Ooty; Yellanahalli, Ooty; Southwick, Ooty; Ooty Radio Telescope; Doddabetta; Nilgiri mountains; Manihatty; Jagathala; Hubbathala; Ooty; St. Stephen&#039;s Church, Ooty; Green fields, Ooty; Assembly rooms theatre; Stone House; Raj Bhavan (Ooty); Ooty Golf Course; Nilgiris district; Aravankad; " theme="Budget, " latitude="11.411828" longitude="76.695356" thumb="http://static.*****.co.in/*****/images/hotelimages/ezimages/ezthumbimg/77469_hotel_view.jpg; ">
<StarRating Level="2"/>
<Address address="Ettines Road" city="Ooty" state="Tamil Nadu" country="India" pincode="643001" location="Tamilagam Road, Ooty Club Internal" phone="0091 - 423 - 2444188" fax="0091 - 423 - 2442461"/>
<image path="http://static.*****.co.in/*****/images/hotelimages/ezimages/77469_hotel_view.jpg"/>
<video/>
<HotelFacility>
<Facility name="Restaurant"/>
<Facility name="Travel Desk"/>
<Facility name="Room Service"/>
<Facility name="Currency Exchange"/>
<Facility name="Parking"/>
<Facility name="Picnic Area"/>
</HotelFacility>
<HotelAmenity Restaurant="1" conference="0" fitness="0" travel="1" forex="1" shopping="0" banquet="0" games="0" Bar="0" Coffee_Shop="0" Room_Service="1" Internet_Access="0" Business_Centre="0" Swimming_Pool="0" Pets="0" Tennis_Court="0" Golf="0" Air_Conditioning="1" Parking="1" Wheel_Chair="0" Health_Club="0"/>
<HotelDistance DistancefromAirport="110" DistancefromStation="1 " DistancefromBus="1.5"/>
<RoomType name="Budget Room">
<Facility name="A/c Room"/>
<Facility name="Attached bath"/>
<Facility name="H/C running water"/>
<Facility name="Cable/satellite TV"/>
<Facility name="Direct-dial phone"/>
</RoomType>
<RoomType name="Superior Room">
<Facility name="A/c Room"/>
<Facility name="Attached bath"/>
<Facility name="H/C running water"/>
<Facility name="Cable/satellite TV"/>
<Facility name="Direct-dial phone"/>
</RoomType>
<RoomType name="Suite">
<Facility name="A/c Room"/>
<Facility name="Attached bath"/>
<Facility name="H/C running water"/>
<Facility name="Cable/satellite TV"/>
<Facility name="Direct-dial phone"/>
</RoomType>
</Hotel>
<hoteldetail index="1" xmlns="http://www.*****.org/OTA/2003/05">
<hotelId id="993" supplier="Desiya">77469</hotelId>
<hotelname>Khems</hotelname>
<currency>INR</currency>
<isReprice>Y</isReprice>
<isProvisionalRequired>Y</isProvisionalRequired>
<ExtraInfo />
<roomDetails>
<room type="Budget Room" mealtype="Room Only" roomid="77469:0" price="830.61" allocation_status="A">
<sub-room index="0" price="755.1">
<offer />
<special_remarks />
<inclusion />
<Supplier_Currency>INR</Supplier_Currency>
<Supplier_Amount>839.0</Supplier_Amount>
<dayWise>
<day no="1">755.1</day>
</dayWise>
</sub-room>
</room>
<room type="Superior Room" mealtype="Room Only" roomid="77469:1" price="1225.62" allocation_status="A">
<sub-room index="1" price="1114.2">
<offer />
<special_remarks />
<inclusion />
<Supplier_Currency>INR</Supplier_Currency>
<Supplier_Amount>1238.0</Supplier_Amount>
<dayWise>
<day no="1">1114.2</day>
</dayWise>
</sub-room>
</room>
</roomDetails>
</hoteldetail>
</Hotels>
</HotelSearchResults>
XSLT
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<div>
<xsl:for-each select="Hotels">
<table width="40%" style="float:left;">
<tr>
<td>
<div>
<table>
<tr>
<td>
<xsl:variable name="link" select="Hotel/image/@path" />
<img id="thumb{position()}" class="thumbnail" src="{$link}" width="240px" height="160px"/>
<div style="position: absolute; margin-top: -68px; text-align: center; width:240px;
background-color: #e5d8ad; color: #482b1b; opacity: 0.7; filter: alpha(opacity=70);
height: 68px;">
<div style="padding-top: 5px;">
<div style="float:left;">
<xsl:value-of select="Hotel/@name"/>
<input type="hidden" id="latitude{position()}" value="{Hotel/@latitude}"></input>
<input type="hidden" id="longitude{position()}" value="{Hotel/@longitude}"></input>
</div>
<div style="float:right;">
<xsl:for-each select="hoteldetail/roomDetails/room">
<xsl:value-of select="@price"/>
</xsl:for-each>
</div>
</div>
</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:1)
试试这个:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:ota="http://www.pepe.org/OTA/2003/05"
exclude-result-prefixes="msxsl ota">
<!-- you must write the correct namespace, of course, neither pepe nor ***** -->
<xsl:output method="xml" indent="yes"/>
<!-- changed match: -->
<xsl:template match="/">
<div>
<!-- changed select: -->
<xsl:for-each select="HotelSearchResults/Hotels">
<table width="40%" style="float:left;">
<tr>
<td>
<div>
<table>
<tr>
<td>
<xsl:variable name="link" select="Hotel/image/@path" />
<img id="thumb{position()}" class="thumbnail" src="{$link}" width="240px" height="160px"/>
<div style="position: absolute; margin-top: -68px; text-align: center; width:240px;
background-color: #e5d8ad; color: #482b1b; opacity: 0.7; filter: alpha(opacity=70);
height: 68px;">
<div style="padding-top: 5px;">
<div style="float:left;">
<xsl:value-of select="Hotel/@name"/>
<input type="hidden" id="latitude{position()}" value="{Hotel/@latitude}"></input>
<input type="hidden" id="longitude{position()}" value="{Hotel/@longitude}"></input>
</div>
<div style="float:right;">
<!-- added namespace: -->
<xsl:for-each select="ota:hoteldetail/ota:roomDetails/ota:room">
<xsl:value-of select="@price"/>
</xsl:for-each>
</div>
</div>
</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>