Assignment No 03
Assignment No 03
Objective:
Problem Statement:
Design the XML document to store the information of the employees of any business
organization and demonstrate the use of:
a) DTD
b) XML Schema
Theory:
What is XML?
XML (eXtensible Markup Language) is used to store and transport data in a structured and
readable format. It is platform-independent and widely used for data exchange between
different systems.
What is XSLT?
XSLT (eXtensible Stylesheet Language Transformations) transforms XML data into
human-readable formats like HTML or PDF. It helps in displaying XML data in a structured
table format.
Why use XSLT with CSS?
• Converts raw XML into a visually appealing table.
• CSS adds styling like colors, borders, and fonts to the output.
• Together, they improve data presentation.
Employees.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE employees SYSTEM "employees.dtd">
<?xml-stylesheet type="text/xsl" href="employees.xsl"?>
<employees xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="employees.xsd">
<employee id="E101" department="HR">
<name>Aarav Sharma</name>
<gender>Male</gender>
<designation>HR Manager</designation>
<salary currency="INR">850000</salary>
<joining_date>2018-03-15</joining_date>
<email>aarav.sharma@example.com</email>
</employee>
<employee id="E102" department="IT">
<name>Priya Verma</name>
<gender>Female</gender>
<designation>Software Engineer</designation>
<salary currency="INR">950000</salary>
<joining_date>2019-07-10</joining_date>
<email>priya.verma@example.com</email>
</employee>
. ..
</employees>
Employees.dtd
<!ELEMENT employees (employee+)>
<!ELEMENT employee (name, gender, designation, salary, joining_date, email)>
<!ATTLIST employee id ID #REQUIRED department CDATA #REQUIRED>
<!ELEMENT name (#PCDATA)>
<!ELEMENT gender (#PCDATA)>
<!ELEMENT designation (#PCDATA)>
<!ELEMENT salary (#PCDATA)>
<!ATTLIST salary currency CDATA #REQUIRED>
<!ELEMENT joining_date (#PCDATA)>
<!ELEMENT email (#PCDATA)>
Employees.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="employees">
<xs:complexType>
<xs:sequence>
<xs:element name="employee" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="gender" type="xs:string"/>
<xs:element name="designation" type="xs:string"/>
<xs:element name="salary">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="currency" type="xs:string" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="joining_date" type="xs:date"/>
<xs:element name="email" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="department" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Style.css
Employees.xsl
<?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" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<title>Employee Information</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<h2>Business Organization Employee Directory</h2>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Gender</th>
<th>Department</th>
<th>Designation</th>
<th>Salary</th>
<th>Joining Date</th>
<th>Email</th>
</tr>
<xsl:for-each select="employees/employee">
<tr>
<td><xsl:value-of select="@id"/></td>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="gender"/></td>
<td><xsl:value-of select="@department"/></td>
<td><xsl:value-of select="designation"/></td>
<td>
<xsl:value-of select="salary"/>
(<xsl:value-of select="salary/@currency"/>)
</td>
<td><xsl:value-of select="joining_date"/></td>
<td><xsl:value-of select="email"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:
Conclusion:
Using XML with DTD or XML Schema ensures the data is structured and validated. XSLT
and CSS help in displaying the data in a user-friendly format, making it easier to read and
understand.