0
我的XML代碼:顯示在XSLT具有特定屬性的元素
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="book.xslt"?>
<bookstore>
<book>
<title lang="eng">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="eng">Learning XML</title>
<price>20.30</price>
</book>
<book>
<title lang="fr">Exploitation Linux</title>
<price>40.00</price>
</book>
</bookstore>
我的XSLT:
<?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>
<table border="1">
<tr>
<th>Book Title</th>
<th>Price</th>
</tr>
<xsl:for-each select="bookstore/book">
<tr>
<td><xsl:value-of select="title[@lang='eng']/text()"/></td>
<td><xsl:value-of select="price/text()"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我想僅對於具有屬性lang="eng"
但i」中的標題顯示詳細信息如果沒有書名,但有價格的話,會得到不必要的行。這是輸出。 感謝您的幫助。
以供將來參考,這是迄今爲止在XSLT問題更加有用的,如果你能證明你目前的和/或所需的輸出作爲實際的HTML/XML源,而不是一個特定瀏覽器如何呈現它的圖片。 – 2014-09-29 17:11:17