You are on page 1of 6

19BPS1126 E2 Kshitij Lariwal

Lab Assignment - 12

CODE Question 1 :


code for xml le:

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


<!DOCTYPE thesaurus SYSTEM "thesaurus.dtd">
<?xml-stylesheet type = "text/xsl" href = "thesaurus.xsl"?>
<thesaurus>
<word content="Neanderthals">
<synonyms>Neandertals</synonyms>
<synonyms>early humans</synonyms>
<synonyms>archaic humans</synonyms>
<antonyms>homo sapiens</antonyms>
</word>
<word content="homoerectus">
<synonyms>Homo erectus</synonyms>
<synonyms>upright man</synonyms>
<antonyms>Neanderthals</antonyms>
<antonyms>homo sapiens</antonyms>
</word>
</thesaurus>

Code for xsl le:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="html"/>

<xsl:template match="/">

<html>
<head>
<title>Thesaurus</title>
fi
fi
19BPS1126 E2 Kshitij Lariwal

</head>
<body style="background-color:lightblue;">
<form method="post" action="">
<table style="border:1px solid black;margin-left:auto;margin-
right:auto;">
<tr>
<td>Enter word:</td>
</tr>
<tr>
<td><input type="text" id="search"/></td>
<td><input type="submit" id="submit" value="Submit"/></td>
</tr>
<xsl:variable name="SearchWord"
select="umbraco.library:Request('submit')"/>
<xsl:for-each select="thesaurus/word[@content=$SearchWord]">
<tr>
<td>ENTERED WORD: <xsl:value-of select="@content"/></td>
</tr>
<tr>
<td>Synonyms: <xsl:for-each select="synonyms"><xsl:value-of
select="."/>, </xsl:for-each></td>
</tr>
<tr>
<td>Antonyms: <xsl:for-each select="antonyms"><xsl:value-of
select="."/>, </xsl:for-each></td>
</tr>
</xsl:for-each>
</table>
</form>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
19BPS1126 E2 Kshitij Lariwal

Code for dtd le:

<!ELEMENT thesaurus (word*)>


<!ELEMENT word (synonyms*, antonyms*)>
<!ATTLIST word content CDATA #IMPLIED>
<!ELEMENT synonyms (#PCDATA)>
<!ELEMENT antonyms (#PCDATA)>
fi
19BPS1126 E2 Kshitij Lariwal

Code for Question 2:


Code for xml le:

<?xml version = "1.0"?>


<?xml-stylesheet type = "text/xsl" href = "employee.xsl"?> <!DOCTYPE class
SYSTEM "employee.dtd">
<class>
<employee number = "1">
<name>Adarsh</name>
<salary>110000</salary>
</employee>
<employee number = "2">
<name>Rahul</name>
<salary>90000</salary>
</employee>
<employee number = "3">
<name>Surya</name>
<salary>150000</salary>
</employee>
<employee number = "4">
<name>Raghvi</name>
<salary>75000</salary>
</employee>
<employee number = "5">
<name>Aditi</name>
<salary>130000</salary>
</employee>
<employee number = "6">
<name>Khushi</name>
<salary>150000</salary>
</employee>
<employee number = "7">
<name>Ajay</name>
<salary>80000</salary>
</employee>
</class>

Code for xsl le:



fi
fi






























19BPS1126 E2 Kshitij Lariwal

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


<!-- xsl stylesheet declaration with xsl namespace: Namespace tells the xlst
processor about which element is to be processed and which is used for output
purpose only --> <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/
1999/XSL/Transform">
<xsl:template match = "/">
<html> <style>
table.center {
width:100%;
margin-left: auto;
margin-right: auto;

}
</style>
<body style="background-color:lightblue;">
<table border = "1" class="center">
<tr bgcolor = "#FFFF00">
<th>Employee Number</th>
<th>Employee Name</th>
<th>Salary</th>
</tr>
<!-- for-each processing instruction
Looks for each element matching the XPath expression
-->
<xsl:for-each select="class/employee">
<xsl:choose>
<xsl:when test="salary > 100000">
<tr bgcolor="green">
<td>
<!-- value-of processing instruction
process the value of the element matching the XPath expression -->
<xsl:value-of select = "@number"/>
</td>
<td><xsl:value-of select = "name"/></td>
<td><xsl:value-of select = "salary"/></td>
<td>Salary greater than 100000</td>
</tr>
</xsl:when>
<xsl:otherwise>
<tr bgcolor="red">



































19BPS1126 E2 Kshitij Lariwal

<td>
<!-- value-of processing instruction
process the value of the element matching the XPath expression -->
<xsl:value-of select = "@number"/>
</td>
<td><xsl:value-of select = "name"/></td>
<td><xsl:value-of select = "salary"/></td>
<td>Salary less than 100000</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Code for dtd le:

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

<!--- Put your DTDDoc comment here. --> <!ELEMENT class (employee)*>
<!--- Put your DTDDoc comment here. --> <!ELEMENT employee (name|
salary)*> <!ATTLIST employee number CDATA #IMPLIED> <!--- Put your
DTDDoc comment here. -->

<!ELEMENT name (#PCDATA)>


<!--- Put your DTDDoc comment here. --> <!ELEMENT salary (#PCDATA)>






fi











You might also like