Web Technology Lab Manual
Assignment No. - 03
TITLE
XML,XSLT and DTD
OBJECTIVES
1. Understand about basic concepts of XML, XSLT and DTD
PROBLEM STATEMENTS
1. 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
And display the content in (e.g., tabular format) by using CSS/XSL.
OUTCOMES
Students will be able to:
1. Develop a XML document to store the information using XML
2. Display the stored content in tabular format using XSLT
SOFTWARE NEEDED
1. Any Operating System
2. Notepad, Notepad ++ or VS Code
3. Web browser
Page 25
Web Technology Lab Manual
THEORY - CONCEPT
eXtensible Markup Language (XML):
XML stands for eXtensible Markup Language
XML is a markup language much like HTML
XML was designed to store and transport data
XML was designed to be self-descriptive
XML is a W3C Recommendation
But still, the XML above does not DO anything. XML is just information wrapped in tags.
The Difference Between XML and HTML
XML and HTML were designed with different goals:
XML was designed to carry data - with focus on what data is
HTML was designed to display data - with focus on how data looks
XML tags are not predefined like HTML tags are
XML Simplifies Things
XML simplifies data sharing
XML simplifies data transport
XML simplifies platform changes
XML simplifies data availability
XML stores data in plain text format. This provides a software- and hardware-independent
way of storing, transporting, and sharing data.
XML also makes it easier to expand or upgrade to new operating systems, new applications,
or new browsers, without losing data.
With XML, data can be available to all kinds of "reading machines" like people, computers,
voice machines, news feeds, etc.
Page 26
Web Technology Lab Manual
eXtensible Stylesheet language transformation (XSLT) :
It is used to transform XML documents into other formats (like transforming XML into HTML).
In HTML documents, tags are predefined but in XML documents, tags are not predefined. World
Wide Web Consortium (W3C) developed XSL to understand and style an XML document, which can
act as XML based Stylesheet Language.
An XSL document specifies how a browser should render an XML document.
Main parts of XSL Document :
o XSLT: It is a language for transforming XML documents into various other types of
documents.
o XPath: It is a language for navigating in XML documents.
o XQuery: It is a language for querying XML documents.
o XSL-FO: It is a language for formatting XML documents.
How XSLT Works ?
The XSLT stylesheet is written in XML format. It is used to define the transformation rules to be
applied on the target XML document. The XSLT processor takes the XSLT stylesheet and applies the
transformation rules on the target XML document and then it generates a formatted document in the
form of XML, HTML, or text format. At the end it is used by XSLT formatter to generate the actual
output and displayed on the end-user.
Page 27
Web Technology Lab Manual
Document Type Definition(DTD):-
A DTD defines the structure and the legal elements and attributes of an XML document.
An XML document with correct syntax is called "Well Formed".
An XML document validated against a DTD is both "Well Formed" and "Valid".
The purpose of a DTD is to define the structure and the legal elements and attributes of an
XML document:
<!DOCTYPE note
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
The DTD above is interpreted like this:
!DOCTYPE note - Defines that the root element of the document is note
!ELEMENT note - Defines that the note element must contain the elements: "to, from,
heading, body"
!ELEMENT to - Defines the to element to be of type "#PCDATA"
!ELEMENT from - Defines the from element to be of type "#PCDATA"
!ELEMENT heading - Defines the heading element to be of type "#PCDATA"
!ELEMENT body - Defines the body element to be of type "#PCDATA"
#PCDATA means parseable character data.
Page 28
Web Technology Lab Manual
DESIGN / EXECUTION STEPS
Following steps are used to Create and Execute web applications,
1. Design xml and xsl files with an extension of .xml and .xsl
2. Link xsl file to xml file.
3. Run the xml file on any browser .
TEST CASES
Manual testing is used to check XSLT get applied or not.
CONCLUSION / ANALYSIS
Hence, we have performed practical no. 3 using concept of XML and XSLT.
PROGRAM CODE & OUTPUT
Following pages required to run this application:
1. employee.xml
2. employee.xsl
Page 29
Web Technology Lab Manual
XML code
Employee.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="employee.xsl" type="text/xsl"?>
<employee>
<e>
<name>Sonali</name>
<id>01</id>
<salary>10000</salary>
</e>
<e>
<name>Manisha</name>
<id>02</id>
<salary>12000</salary>
</e>
<e>
<name>Swati</name>
<id>03</id>
<salary>14000</salary>
</e>
<e>
<name>Sakshi</name>
<id>04</id>
<salary>16000</salary>
</e>
<e>
<name>Reyansh</name>
<id>05</id>
<salary>20000</salary>
</e>
</employee>
Page 30
Web Technology Lab Manual
XSL code
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>
<h3>Employee</h3>
<table border ="2">
<tr bgcolor="lightred">
<th>name</th>
<th>id</th>
<th>salary</th>
</tr>
<xsl:for-each select="e/employee">
<tr>
<td><xsl:value-of select = "name"/></td>
<td><xsl:value-of select = "id"/></td>
<td><xsl:value-of select = "salary"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Page 31
Web Technology Lab Manual
OUTPUT :
Page 32
Web Technology Lab Manual
ORAL QUESTIONS
1. What is XML?
2. What is XSLT?
3. What is the purpose of DTD ?
4. What is the syntax of xsl and xml ?
Page 33