My XML codes:
<?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>
My XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR">
<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>
I would like to display the details only for the title which have attribute lang="eng" but i'm getting an unnecessary row where there's no book title but there's the price. Here's the output. Thanks for your help.
No comments:
Post a Comment