使用XSL显示XML引用



我的XML文件:

<?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>

这是我目前使用的XSL:

<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如何使用XSLT在html表中显示standort1的书籍?目前我只能简单地显示所有的书,但我想使用id/iref为不同的书店列出一个列表

使用来解决交叉引用。这里有一个例子:

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>

最新更新