Search code examples
xmlxsltdtd

why is my xml page not being displayed despite correct dtd and xsl?


I am trying to design an xml to display details of a student in a college . The college comprises of students with paramters name , age and roll.

Here is my xml file

<?xml version="1.0"?>
<!DOCTYPE college SYSTEM "college.DTD">
<?xsl-stylesheet  type="text/xsl" href="college.XSL"?>

<college>

<student>
<name>vipul</name>
<age>16</age>
<roll>12</roll>
</student>

<student>
<name>vipul</name>
<age>16</age>
<roll>12</roll>
</student>

<student>
<name>vipul</name>
<age>16</age>
<roll>12</roll>
</student>

</college>

This is my xsl file

<?xml version="1.0"?>
<xsl-stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">

    <html>
    <head>
    <title>college</title>
    <head>

    <body>
    <table border="1" align="center">
    <tr bgcolor="yellow">
    <th>name</th>
    <th>age</th>
    <th>roll</th>
    </tr>

    <xsl:for-each select="college/student">
    <tr>
    <td><xsl:value-of select="name" /></td>
    <td><xsl:value-of select="age" /></td>
    <td><xsl:value-of select="roll" /></td>
    </tr>
    </xsl:for-each>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

And finally this is my external dtd file . Here i have defined the relevant code structure

<?xml version="1.0">
<!DOCTYPE college(student)>
<!ELEMENT student(name,age,roll)>
<!ELEMENT name(#PCDATA)>
<!ELEMENT age(#PCDATA)>
<!ELEMENT roll(#PCDATA)>

everything seems to be correct ,yet i am not getting my desired xml output . why is this happening ?


Solution

  • There are two errors with your files:

    1. Your DTD file is invalid. See this answer. It explains that external DTD files must not contain a

      <!DOCTYPE college(student)>
      

      declaration. So your DTD file should simply look like (I added a + to your college element to enable multiple student children)

      <?xml version="1.0" encoding="utf-8" ?>
      <!ELEMENT college (student+)>
      <!ELEMENT student (name,age,roll)>
      <!ELEMENT name (#PCDATA)>
      <!ELEMENT age (#PCDATA)>
      <!ELEMENT roll (#PCDATA)>
      
    2. Your browser does not recognize the link to your XSLT code in your XML file, because you have a typo in your declaration. The correct spelling in the beginning of your XML file is

      <?xml-stylesheet... 
      

      instead of

      <?xsl-stylesheet....