Results 1 to 4 of 4

Thread: Some help with XML and XSL please.

  1. #1
    Senior Member Nemeliza's Avatar
    Join Date
    Jul 2003
    Posts
    1,719
    Thanks
    1
    Thanked
    5 times in 5 posts

    Some help with XML and XSL please.

    I am having some headache with this XML and XSL; I’m looking at it and can’t figure out why it does not work. Maybe some other eyes will be able to spot my mistake as I must be missing something here.

    2 documents: lecturers.xml and lecturers.xsl. I can't get the XSL templates formatting to work, all i see is the heading[h1] and an empty table (only table headings are populated[th]).

    lecturers.xml
    Code:
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="lecturers.xsl" ?>
    <!DOCTYPE lecturers [
    	<!ELEMENT lecturers (lecturer+)>
    	<!ELEMENT lecturer (name)>
    	<!ELEMENT name (teaching, research)>
    	<!ELEMENT teaching (course+)>
    	<!ELEMENT course (#PCDATA)>
    	<!ELEMENT research (#PCDATA)>
    	<!ATTLIST name
    	title CDATA "title"
    		first CDATA "first name"
    		last CDATA "last name"
    >
    	<!ATTLIST course
    	code ID #REQUIRED
    >
    ]>
    <lecturers>
    	<lecturer>
    		<name title="Professor" first="Peter" last="Quirk">
    			<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>
    		</name>
    	</lecturer>
    	<lecturer>
    		<name title="Professor" first="John" last="Doe">
    			<teaching>
    				<course code="CO3100">Advanced Multimedia</course>
    				<course code="CO3390">Flash MX</course>
    			</teaching>
    			<research>
    			The application of Web protocols to Biology
    		</research>
    		</name>
    	</lecturer>
    </lecturers>
    lecturers.xsl
    Code:
    <?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>Lecturers</title>
    </head>
    <body>
    <h1>Lecturers</h1>
    <table border = "1">
    	<tr>
    		<th>Title</th>
    		<th>Name</th>
    		<th>Teaching</th>
    		<th>Research</th>
    	</tr>
    		<xsl:for-each select="lecturers/lecturer">
    	<tr>
    		<td><xsl:value-of select="lecturers/lecturer/name/@title" /></td>
    		<td><xsl:value-of select="lecturers/lecturer/name/@name" /></td>
    		<td><xsl:value-of select="lecturers/lecturer/teaching/course" /></td>
    		<td><xsl:value-of select="lecturers/lecturer/research" /></td>
    	</tr>
    		</xsl:for-each>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>
    Thanks in advance.

  2. #2
    Senior Member Nemeliza's Avatar
    Join Date
    Jul 2003
    Posts
    1,719
    Thanks
    1
    Thanked
    5 times in 5 posts
    Ignore this thread, It was late and i had been typing code for too long.
    This is a prime example of why people should have breaks when working.

    Schoolboy errors...

  3. #3
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    There's somthing perverse about having an XML file based upon a dtd when the XSL file is based upon the XML Transform schema which is based upon the XML schema which is based upon a dtd anyway!

    All roads lead to SGML I guess.
    To err is human. To really foul things up ... you need a computer.

  4. #4
    HEXUS.net Webmaster
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3,108
    Thanks
    1
    Thanked
    0 times in 0 posts
    If you can post up the solution to your issue it always helps in case someone hits a similar problem

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •