I'm having problems with rogue/repeated output with an XSLT transformation to a HTML document. I'm outputting some records to a table and the data appears outside the table as well as, correctly, inside the table.
short output:
<table>
<tr>
<td>Fred</td><td>Bloggs</td>
</tr>
</table>
Fred Bloggs
(Fred Bloggs repeated incorrectly at the bottom despite being in the XML file once)
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="APTfile/Message">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="Header">
<table border="2">
<tr>
<th>Document Name</th>
<th>APT Version</th>
<th>Supplier ID</th>
<th>From LEA</th>
<th>Destination LEA</th>
<th>Date-Time</th>
<th>Entry Year- Month</th>
<th>Entry Year Group</th>
</tr>
<tr>
<td><xsl:value-of select="DocumentName"/></td>
<td><xsl:value-of select="APTversion"/></td>
<td><xsl:value-of select="SupplierID"/></td>
<td><xsl:value-of select="SourceLEA"/></td>
<td><xsl:value-of select="DestinationLEA"/></td>
<td><xsl:value-of select="DateTime"/></td>
<td><xsl:value-of select="EntryYearAndMonth"/></td>
<td><xsl:value-of select="EntryYearGroup"/></td>
</tr>
</table>
</xsl:template>
<xsl:template match="Pupils/Pupil">
<p>
<table border ="2">
<tr>
<th>UPN</th>
<th >Surname</th>
<th>Forename</th>
<th>DOB</th>
<th>Gender</th>
<th>Statemented</th>
</tr>
<tr>
<td><xsl:value-of select="UPN"/></td>
<td><xsl:value-of select="Surname"/></td>
<td><xsl:value-of select="Forename"/></td>
<td><xsl:value-of select="DOB"/></td>
<td><xsl:value-of select="Gender"/></td>
<td><xsl:value-of select="Statemented"/></td>
</tr>
<tr>
<th colspan="7">Current School</th>
</tr>
<tr>
<th colspan="3" >LEA</th>
<th colspan="3">DfES</th>
</tr>
<tr>
<td colspan="3"><xsl:value-of select="CurrentSchool/LEA"/></td>
<td colspan="3"><xsl:value-of select="CurrentSchool/Estab"/></td>
</tr>
</table>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="Address/BS7666Address">
<table border="2">
<tr>
<th colspan="7">BS7666 Address</th>
</tr>
<tr>
<td>PAON</td>
<td>Street</td>
<td>Town</td>
<td>Administrative Area</td>
<td>Postcode</td>
<td>Country</td>
</tr>
<tr>
<td><xsl:value-of select="PAON"/></td>
<td><xsl:value-of select="Street"/></td>
<td><xsl:value-of select="Town"/></td>
<td><xsl:value-of select="AdministrativeArea"/></td>
<td><xsl:value-of select="Postcode"/></td>
<td><xsl:value-of select="Country"/></td>
</tr>
</table>
</xsl:template>
<xsl:template match="Address/AddressLines">
<table border="2">
<tr>
<th>Unstructured Address</th>
</tr>
<tr>
<td>Line 1</td>
<td>Line 2</td>
<td>Line 3</td>
<td>Line 4</td>
<td>Line 5</td>
</tr>
<tr>
<td><xsl:value-of select="Line1"/></td>
<td><xsl:value-of select="Line2"/></td>
<td><xsl:value-of select="Line3"/></td>
<td><xsl:value-of select="Line4"/></td>
<td><xsl:value-of select="Line5"/></td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
XML Data used:
<?xml version="1.0" encoding="UTF-8"?>
<APTfile>
<Message>
<Header>
<DocumentName>Pre Data Transfer File</DocumentName>
<APTversion>2.3</APTversion>
<SupplierID>EMS </SupplierID>
<SourceLEA>371</SourceLEA>
<DestinationLEA>815</DestinationLEA>
<DateTime>2007-07-19T15:10:43</DateTime>
<EntryYearAndMonth>2008-09</EntryYearAndMonth>
<EntryYearGroup>7</EntryYearGroup>
</Header>
<Pupils>
<Pupil>
<UPN>sdgdfgdfgdf</UPN>
<Surname>Fred</Surname>
<Forename>Blogs</Forename>
<DOB>1997-07-15</DOB>
<Gender>M</Gender>
<CurrentSchool>
<LEA>371</LEA>
<Estab>2088</Estab>
</CurrentSchool>
<Statemented>false</Statemented>
<Address>
<BS7666Address>
<PAON>dfgdfgdfg</PAON>
<Street>dfgdfg</Street>
<Town>dgfdf</Town>
<AdministrativeArea>dfgdfgdf</AdministrativeArea>
<Postcode>dgdfgdf</Postcode>
<Country>dfgdfdf</Country>
</BS7666Address>
</Address>
</Pupil>
<Pupil>
<UPN>dfgdfgffd</UPN>
<Surname>dfg</Surname>
<Forename>hgfhgfhgf</Forename>
<DOB>1997-07-15</DOB>
<Gender>F</Gender>
<CurrentSchool>
<LEA>371</LEA>
<Estab>2088</Estab>
</CurrentSchool>
<Statemented>false</Statemented>
<Address>
<BS7666Address>
<PAON>bgfhd</PAON>
<Street>dfgh</Street>
<Town>dfghdfh</Town>
<AdministrativeArea>gfdhgd</AdministrativeArea>
<Postcode>fdhdg</Postcode>
<Country>UK</Country>
</BS7666Address>
</Address>
</Pupil>
</Pupils>
</Message>
</APTfile>
Any ideas on why the Pupil data is appearing inside the table as well as being repeated outside? It is probably a basic basic mistake, but I'm stumped.
Thanks.