0% found this document useful (0 votes)
10 views9 pages

Wipunit5 Programs

The document outlines the creation and validation of XML documents for voter and student details using DTD and XSLT. It includes examples of XML structures, DTD definitions, and XSLT code to display data in a tabular format. Additionally, it provides an example of an XML document for sports and its corresponding XSLT for presentation.

Uploaded by

priya j
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views9 pages

Wipunit5 Programs

The document outlines the creation and validation of XML documents for voter and student details using DTD and XSLT. It includes examples of XML structures, DTD definitions, and XSLT code to display data in a tabular format. Additionally, it provides an example of an XML document for sports and its corresponding XSLT for presentation.

Uploaded by

priya j
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1) Discover a XML document to store voter ID, voter name, address and date of birth details and

validate the document with the help of DTD.

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.

Name Regno Mark

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

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE student SYSTEM "student.dtd">

<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:

<? xml version = "1.0" encoding = "UTF-8">


<! DOCTYPE student
[ <! Element student (info+)>
<! Element info (name, regno, mark )>
<! Element name(#PCDATA)>
<! Element regno # REQUIRED>
<! Element mark (#PCDATA)>
]>

Student.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>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">

<xsl:sort select="Marks" order="descending"/>

<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:

Name Regno Mark

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

<?xml version = "1.0"?>


<class>
<employee id = "001">
<firstname>Aryan</firstname>
<lastname>Gupta</lastname>
<nickname>Raju</nickname>
<salary>30000</salary>
</employee>
<employee id = "024">
<firstname>Sara</firstname>
<lastname>Khan</lastname>
<nickname>Zoya</nickname>
<salary>25000</salary>
</employee>
<employee id = "056"> <firstname>Sara</firstname>
<lastname>Khan</lastname>
<nickname>Zoya</nickname>
<salary>25000</salary>
</employee>
<employee id = "056">
<firstname>Peter</firstname>
<lastname>Symon</lastname>
<nickname>John</nickname>
<salary>10000</salary>
</employee>
</class>

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>

<xsl:value-of select = "@id"/>


</td>
<td><xsl:value-of select = "firstname"/></td>
<td><xsl:value-of select = "lastname"/></td>
<td><xsl:value-of select = "nickname"/></td>
<td><xsl:value-of select = "salary"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Update employee.xml document with the following xml-stylesheet tag. Set href value to
employee.xsl

<?xml version = "1.0"?>


<?xml-stylesheet type = "text/xsl" href = "employee.xsl"?>
<class>
...
</class>

Updated "employee.xml"

<?xml version = "1.0"?>

<?xml-stylesheet type = "text/xsl" href = "employee.xsl"?>


<class>
<employee id = "001">
<firstname>Aryan</firstname>
<lastname>Gupta</lastname>
<nickname>Raju</nickname>
<salary>30000</salary>
</employee>
<employee id = "024">
<firstname>Sara</firstname>
<lastname>Khan</lastname>
<nickname>Zoya</nickname>
<salary>25000</salary>
</employee>
<employee id = "056">
<firstname>Peter</firstname>
<lastname>Symon</lastname>
<nickname>John</nickname>
<salary>10000</salary>
</employee>
</class>

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:

<?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>
<h1 align="center">Sports Details</h1>
<table border="3" align="center" >
<tr>
<th>Name</th>
<th>Descrition</th>

</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

You might also like