Professional Documents
Culture Documents
Unit-IV XML
Unit-IV XML
Research, Indore
www.acropolis.in
Department of Computer Science and
Engineering
Unit-IV
XML
<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash
browns</description>
<calories>950</calories>
</food>
</breakfast_menu>
December 13, 2023 gajendrachouhan@acropolis.in 16
Transform the XML document with XSLT
<?xml version="1.0" encoding="UTF-8"? <xsl:value-of select="price"/>
> </div>
<html xsl:version="1.0" xmlns:xsl="http: <div style="margin-left:20px;margin-
//www.w3.org/1999/XSL/Transform"> bottom:1em;font-size:10pt">
<body style="font-family:Arial;font- <p>
size:12pt;background-color:#EEEEEE"> <xsl:value-of select="description"/>
<xsl:for-each select="breakfast_menu/ <span style="font-
food"> style:italic"> (<xsl:value-
<div style="background- of select="calories"/> calories per
color:teal;color:white;padding:4px"> serving)</span>
<span style="font- </p> </div></xsl:for-each></body><
weight:bold"><xsl:value- /html>
of select="name"/> - </span>
December 13, 2023 gajendrachouhan@acropolis.in 17
DTD
❖ The purpose of a DTD (Document Type Definition) is to define the structure
of an XML document. It defines the structure with a list of legal elements:
<!DOCTYPE note [
<!ELEMENT note ( to, from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
December 13, 2023 gajendrachouhan@acropolis.in 18
Cont….
❖ 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"