數據我有XML
這樣的代碼:如何獲得在XSL文件
<hotels>
<hotel contact="(855) 23 430 732">
<name>hotel A</name>
<type>hotel or apartment</type>
<rating>1 to 5</rating>
<address>
<houseNo>73 </houseNo>
<street>Preah Monivong Blvd </street>
<Sangkat>Mean Chey</Sangkat >
<Khan>Daun Penh</Khan>
<city>Bangkok</city>
</address>
<room>
<roomType>hotel: standard/deluxe, apartment: studio/2-bedroom/3-bedroom</roomType>
<price>209</price>
<description>Descriptions</description>
</room>
<room>
<roomType>hotel: standard/deluxe, apartment: studio/2-bedroom/3-bedroom</roomType>
<price>210</price>
<description>Descriptions</description>
</room>
<room>
.....
</room>
</hotel>
<hotel contact="...">
... ...
... ...
</hotel>
</hotels>
使用xsl
代碼我該怎麼讀呢?這是我的代碼:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>test xsl</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left;">Name</th>
<th style="text-align:left;">Type</th>
<th style="text-align:left;">Rating</th>
<th style="text-align:left;">Address</th>
<th style="text-align:left;">Room</th>
</tr>
<xsl:for-each select="hotels/hotel">
<tr>
<!--<xsl:value-of select="."/>-->
<td><xsl:value-of select="name" /></td>
<td><xsl:value-of select="type" /></td>
<td><xsl:value-of select="rating" /></td>
<td><xsl:value-of select="address" /></td>
<td><xsl:value-of select="room" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
問題我的代碼是什麼錯誤,但對於<room>
可以只加載的第一個孩子。任何一個有經驗的xsl
請幫我解決這個問題
請張貼一個完整的樣式表**和**預期的結果。 - **提示**:您需要使用另一個'xsl:for-each'或'xsl:apply-templates'來處理房間。 –
請再次檢查,我編輯準備 – Songs
我仍然沒有看到預期的結果。您正在爲每家酒店創建一個行:您如何期望在單行中顯示多個房間? –