Reputation: 23
My XML File:
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="bookstorex.xsl"?>
<company>
<bookstore>
<standort1 standort-id="h_1"></standort1>
<standort2 standort-id="h_2"></standort2>
</bookstore>
<book_list>
<book category="cooking" book-id="b_1" standort-id="h_1">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children" book-id="b_2" standort-id="h_2">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</book_list>
</company>
This is the XSL im using at the moment:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="book_list">
<html>
<body>
<h1>Mein Bookstore</h1>
<table border = "2">
<tr>
<th>Bookname</th>
<th>Author</th>
<th>Year</th>
<th>price</th>
</tr>
<xsl:for-each select = "book">
<tr>
<td>
<xsl:value-of select = "title"/>
</td>
<td>
<xsl:value-of select = "author"/>
</td>
<td>
<xsl:value-of select = "year"/>
</td>
<td>
<xsl:value-of select = "price"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Yo how can i display the books of standort1 inside a html table with XSLT? At the moment im only able to simply display all books but i want to use id/idref to make a list for different bookstores
Upvotes: 0
Views: 175
Reputation: 116992
Use a key to resolve cross-references. Here's an example:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="book-by-location" match="book" use="@standort-id"/>
<xsl:template match="/company">
<html>
<body>
<xsl:for-each select="bookstore/*">
<h1>
<xsl:text>Location </xsl:text>
<xsl:value-of select="@standort-id"/>
</h1>
<table border="2">
<tr>
<th>Bookname</th>
<th>Author</th>
<th>Year</th>
<th>price</th>
</tr>
<xsl:for-each select="key('book-by-location', @standort-id)">
<tr>
<td>
<xsl:value-of select="title"/>
</td>
<td>
<xsl:value-of select="author"/>
</td>
<td>
<xsl:value-of select="year"/>
</td>
<td>
<xsl:value-of select="price"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1