Note 1: This is my first question here. Please be gentle.
Note 2: Yes, this is homework. I hate to ask for help, but I've hit a brick wall. If you don't want to tell me the answer, suggesting where to look for the answer would be equally appreciated. Thank you.
I'm trying to write an XSLT sheet that looks at the genre attribute of each DVD element in the target XML file. It is supposed to return a list with each of the different values listed exactly once with a count of the number of times each value was found.
I think my XPath is wrong. To debug, I've tried using <xsl:value-of select="foo">
statements to try different XPath queries, but I haven't had any luck.
Here's the XSL file (I've tried to strip it to the brass tacks)
<?xml version="1.0" encoding="UTF-8"?>
<!-- BrowseAllExample.xsl -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:key name="genres" match="DVD" use="@genre" />
<xsl:template match="/">
<html>
<head>
<title>Browse: DVDs by Genre</title>
<link href="../style/browseByGenre.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- TODO: insert page header here -->
<h2>Browse by Genre</h2>
<div>
<!-- This doesn't seem to select anything
I've tried lots of combinations with a test
xsl:value-of-select element, but nothing
seems to work as a selector except "*"
-->
<xsl:apply-templates select="/dvdlist/DVD[not(@genre=preceding-sibling/@genre)]"
mode="genreList">
<xsl:sort select="@genre"/>
</xsl:apply-templates>
</div>
</body>
</html>
</xsl:template>
<!--
List each genre and count titles in each
-->
<xsl:template match="DVD" mode="genreList">
<a href="#{generate-id()}"><xsl:value-of select="@genre"/></a> (<xsl:value-of
select="count(key('genres',@genre))"/>) -
</xsl:template>
</xsl:stylesheet>
Here's the relevant part of the XML file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- dvdlistExample.xml -->
<?xml-stylesheet type="text/xsl" href="BrowseAllExample.xsl"?>
<dvdlist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example.com/dvdlist ./schema/dvdlist.xsd"
xmlns="http://example.com/dvdlist">
<DVD genre="Comedy" itemnum="ID-20">
<title>American Wedding</title>
<year>2003</year>
<price>18.89</price>
<talent>
<director>Jesse Dylan</director>
<actor>Jason Biggs</actor>
<actor>Sean William Scott</actor>
<actor/>
</talent>
<ratings mpaa="NR" customer="3"/>
<pics id="ID-20">
<thumbnail>Wedding-small.jpg</thumbnail>
<large>Wedding-big.jpg</large>
</pics>
</DVD>
<DVD genre="Action" itemnum="ID-2">
<title>Badboys II</title>
<year>2003</year>
<price>20.27</price>
<talent>
<director>Michael Bay</director>
<actor>Will Smith</actor>
<actor>Martin Lawrence</actor>
</talent>
<ratings mpaa="R" customer="3"/>
<pics id="ID-2">
<thumbnail>Badboys-small.jpg</thumbnail>
<large>Badboys-big.jpg</large>
</pics>
</DVD>
<!--Other DVD entries removed to save space-->
</dvdlist>