Basic XML/XSLT : applying template to several elements



I am trying to teach myself XSLT. This may be a very basic question but after a lot of searching here, and across other sites on the web, I have still been unable to solve this problem.


I have been trying to recreate the scenario described in this question: How can you deal with embedded XML tags in XSLT?



<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.html.xsl"?>
<favoriteMovies>
<favoriteMovie>the <i>Star Wars</i> saga</favoriteMovie>
</favoriteMovies>


Here is the XSL:



<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:output method="html" omit-xml-declaration="yes" indent="yes"/>

<xsl:template match="/">
<html>
<head />
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="/*">
<ul>
<xsl:apply-templates/>
</ul>
</xsl:template>

<xsl:template match="favoriteMovie">
<li><xsl:copy-of select="node()"/></li>
</xsl:template>
</xsl:stylesheet>


This works fine for this particular example. But when I add another "favourite movie"...



<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.html.xsl"?>
<favoriteMovies>
<favoriteMovie>the <i>Star Wars</i> saga</favoriteMovie>
</favoriteMovies>
<favoriteMovies>
<favoriteMovie>the <i>Godfather</i> trilogy</favoriteMovie>
</favoriteMovies>


all I get is an error...



XML Parsing Error: junk after document element Location: localhost:8888/test.xml Line Number 6, Column 1: ^



What would I need to change to make this work?


No comments:

Post a Comment