Wipunit5 Programs
Wipunit5 Programs
INTERNAL DTD:
<? xml version = "1.0" encoding = "UTF-8">
<! DOCTYPE Voter
[ <! Element Voter (Id, Name, Address, Date_of_birth)>
<! Element Id (#PCDATA)>
<! Element Name (#PCDATA)>
<! Element Address (#PCDATA)>
<! Element Date_of_birth (#PCDATA)>
]>
<Voter >
<Id> Voter Id = FGK99567 </Id>
<Name> Voter Name = Mohan Kumar </Name>
<Address> Address = Assam </Address>
<Date_of_birth> Date of birth = 05-03-1991 </Date_of_birth>
</Voter >
EXTERNAL DTD:
Vote.xml
<?xml version="1.0"?>
<!DOCTYPE voter SYSTEM "vote.dtd">
<Voter >
<Id> Voter Id = FGK99567 </Id>
<Name> Voter Name = Mohan Kumar </Name>
<Address> Address = Assam </Address>
<Date_of_birth> Date of birth = 05-03-1991 </Date_of_birth>
</Voter >
Vote.dtd
<! Element Voter (Id, Name, Address, Date_of_birth)>
<! Element Id (#PCDATA)>
<! Element Name (#PCDATA)>
<! Element Address (#PCDATA)>
<! Element Date_of_birth (#PCDATA)>
2) Generate DTD for the XML document. Get the students details like name, register number and
mark using form.
XYZ 1000 90
ABC 1001 80
RST 1002 89
PQR 1003 87
Generate the collected information in the descending order of marks using XSLT. Results should be
displayed in the above format. Write a source code and explain the same.
Student.xml
<student>
<info>
<name>xyz </name>
<regno>1000</regno>
<mark>90</mark>
</info>
<info>
<name>ABC </name>
<regno>1001</regno>
<mark>80</mark>
</info>
<info>
<name>RST</name>
<regno>1002</regno>
<mark>89</mark>
</info>
<info>
<name>PQR</name>
<regno>1003</regno>
<mark>87</mark>
</info>
</student>
Student.dtd:
Student.xsl:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Student Details</h2>
<table border="1">
<tr bgcolor="blue">
<th>Name</th>
<th>Reg no</th>
<th>Mark</th>
</tr>
<xsl:for-each select="student/info">
<tr>
<td><xsl:value-of select="Name"/></td>
<td><xsl:value-of select="Regno"/></td>
<td><xsl:value-of select="Mark"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:
XYZ 1000 90
RST 1002 89
PQR 1003 87
ABC 1001 80
3)Develop XSLT code to display employee details in a Table form which is stored is XML
employee.xml
employee.xsl
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "/">
<html>
<body>
<h2>Employee</h2>
<table border = "1"> <tr bgcolor = "#9acd32">
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Nick Name</th>
<th>Salary</th>
</tr>
<xsl:for-each select="class/employee">
<tr>
<td>
Update employee.xml document with the following xml-stylesheet tag. Set href value to
employee.xsl
Updated "employee.xml"
Output:
4)Create an XML document that marks up various sports and their descriptions. Use XSLT to
tabulate neatly the elements and attributes of the document
Sports.xml:
<sports>
<name>Auto race</name>
<desc>a Japanese motorcycle speedway</desc>
<name>Axe throwing</name>
<desc>competitors throw axes at a circular target.</desc>
<name>Badminton</name>
<desc>an indoor game with rackets</desc>
<name>Baseball</name>
<desc>a bat and ball game</desc>
<name>chess boxing</name>
<desc>a combination of chess and boxing.</desc>
</sports>
Sports.xsl:
</tr>
<xsl:for-each select="sports">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="desc"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:
Sports Details
Name Description
Auto race a Japanese motorcycle speedway
Axe throwing competitors throw axes at a circular target
Badminton an indoor game with rackets
Baseball a bat and ball game
chess boxing a combination of chess and boxing