I have some problems excluding unwanted output from my xlst transformation.
I already know about the default rules behind match etc, but i’m not able to use match in template/apply-templates properly.
Can you help me fixing this please?
So I have an XML file structured this way:
<movies>
<movie id="0">
<title>Title</title>
<year>2007</year>
<duration>113</duration>
<country>Country</country>
<plot>Plot</plot>
<poster>img/posters/0.jpg</poster>
<genres>
<genre>Genre1</genre>
<genre>Genre2</genre>
</genres>
...
</movie>
...
</movies>
And I want to create a html UL list with a LI for each movie that belongs to a genre ‘#######'(replaced at runtime by my perl script) which is a link to a page(named by its id).
Right now i’m doing it this way:
<xsl:template match="/">
<h2> List </h2>
<ul>
<xsl:apply-templates match="movie[genres/genre='#######']"/>
<li>
<a>
<xsl:attribute name="href">
/movies/<xsl:value-of select= "@id" />.html
</xsl:attribute>
<xsl:value-of select= "title"/>
</a>
</li>
</ul>
</xsl:template>
Obviously this way it shows me all the elements of the movies that matches the chosen genre.
Do I have to add tons of <xsl:template match="..."> to remove all the extra output?
Can you please teach me the correct way to create an html snippet like this?
List
Thank you in advance!
You are almost there – your use of apply-templates is causing you the problem.
Instead, structure your XSLT this way:
It will apply the spcific template (match=”movie”) to your movie element. In your original attempt, you will be using the default template which will bring back everything contained within a movie element.