Xml 在XSLT中显示具有特定属性的元素
我的XML代码:Xml 在XSLT中显示具有特定属性的元素,xml,xslt,Xml,Xslt,我的XML代码: <?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>
<?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>
哈利·波特
29.99
学习XML
20.30
利用Linux
40
我的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”
的标题的详细信息,但我得到了一个不必要的行,其中没有书名,但有价格。这是输出。
谢谢你的帮助
您需要将使用
处理的每个元素限制为使用适当语言标题的元素:
<xsl:for-each select="bookstore/book[title/@lang = 'eng']">
作为将来的参考,如果您可以将当前和/或所需的输出显示为实际的HTML/XML源,而不是一个特定浏览器如何呈现它的图片,那么它在XSLT问题中会更有用。
<td><xsl:value-of select="price"/></td>