I've started playing around with XSLT, and am having a few issues. I've managed to output my XML document using a series of value-of select instructions, but I'm really struggling when it comes to writing my XSLT templates myself.
Here's my XML:
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="lecturers.xsl"?>
<lecturers>
<lecturer>
<name>
<title>Professor</title>
<first>Peter </first> <last>Quirk</last>
</name>
<teaching>
<course code="CO3070">XML and the Web</course>
<course code="CO3300"> Web Server Architectures</course>
</teaching>
<research>
The application of Web protocols to Biology
</research>
</lecturer>
<lecturer>
<name>
<title>Doctor</title>
<first>Brian </first> <last>Johnson</last>
</name>
<teaching>
<course code="CO9999">Computer Hacking</course>
<course code="CO3300"> Web Server Architectures</course>
</teaching>
<research>
Investigating the various complexities of Computer Hacking
</research>
</lecturer>
Then, this is my XSL as it currently stands:
<?xml version="1.0"?>
<xsl:stylesheet version='1.0' xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" />
<xsl:template match="/">
<html>
<head>
<title>XML Week 7</title>
</head>
<body>
<h1>Week 7: Lecturers file turned to XSL:Template</h1>
<table border="1">
<tr>
<th><b>Title</b></th>
<th><b>Name</b></th>
<th><b>Teaching</b></th>
<th><b>Research</b></th>
</tr>
<tr>
<td><xsl:value-of select="lecturers/lecturer/name/title" /></td>
<td><xsl:value-of select="lecturers/lecturer/name/first" /><xsl:text> </xsl:text><xsl:value-of select="lecturers/lecturer/name/last" /></td>
<td><xsl:value-of select="lecturers/lecturer/teaching/course" /> and <xsl:value-of select="(lecturers/lecturer/teaching/course)[2]" /></td>
<td><xsl:value-of select="lecturers/lecturer/research" /></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
This does output the information I need into a table, but I've been instructed to create new templates to hold the lecturer element, and then the course children of that element. I might just be over-complicating things in my head, but I just cannot get it to work, whenever I try to apply a template to one of the td's I just get a parsing error in the browser. So, does anyone have any tips for me? Would be much appreciated, even some basic examples to explain how to get it working in my example would be superb. Cheers guys.