Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 27th, 2007, 08:00 AM
Registered User
 
Join Date: Jul 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Rogue output in results

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.

 
Old July 27th, 2007, 04:24 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In your match="Pupils/Pupil" template, you output the child elements once when you do

            <td><xsl:value-of select="Surname"/></td>
            <td><xsl:value-of select="Forename"/></td>

and again when you do

<xsl:apply-templates/>

at the end.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
two methods different results hahaha568 BOOK: Beginning SQL 0 February 10th, 2008 09:47 AM
Edit Query Results in Results Grid druid2112 SQL Server 2005 1 June 28th, 2007 08:49 AM
display results carswelljr ASP.NET 2.0 Basics 1 April 19th, 2007 09:46 AM
different results were given for the same query madhusrp SQL Server 2000 2 May 9th, 2006 01:54 AM
SP with Results sidneyfuerte Pro VB 6 4 September 9th, 2003 01:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.