Professional Documents
Culture Documents
HTML tags Used for formatting purpose. XSLT Processor will skip them
and browser will simply render them.
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<book>
<title> XML for Web</title>
<author>Winston</author>
<publication>Pearson</publication>
<edition>8</edition>
<price>932Rs</price>
</book>
<book>
<title> XML for Web</title>
<author>Winston</author>
<publication>Pearson</publication>
<edition>8</edition>
<price>932Rs</price>
</book>
<book>
<title> XML for Web</title>
<author>Winston</author>
<publication>Pearson</publication>
<edition>8</edition>
<price>932Rs</price>
</book>
<book>
<title> XML for Web</title>
<author>Winston</author>
<publication>Pearson</publication>
<edition>8</edition>
<price>932Rs</price>
</book>
</catalog>
//mystyle1.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<html>
<body>
<table align="center" border="1">
<caption> <h2>Books Information</h2></caption>
<tr bgcolor="#BBEEFF">
<th style="text-align:left">Title</th>
<th style="text-align:left">Author</th>
<th style="text-align:left">Publication</th>
<th style="text-align:left">Edition</th>
<th style="text-align:left">Price</th>
</tr>
<xsl:for-each select="catalog/book">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="author"/></td>
<td><xsl:value-of select="publication"/></td>
<td><xsl:value-of select="edition"/> </td>
<td><xsl:value-of select="price"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
//Example to Present Student Information student.xml
<html>
<body>
<h2>Students</h2>
<xsl:for-each select="class/student">
<tr>
<!-- @ is used to access attribute -->
<td><xsl:value-of select = "@rollno"/></td>
<td><xsl:value-of select = "firstname"/></td>
<td><xsl:value-of select = "lastname"/></td>
<td><xsl:value-of select = "marks"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
//sorting data based on particular element (sort)-stud.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>Students</h2>
<table border = "1">
<tr bgcolor = "#9acd32">
<th>Roll No</th>
<th>First Name</th>
<th>Last Name</th>
<th>Marks</th>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
//using choose, when otherwise-studstyle2.xsl
<tr>
<td><xsl:value-of select = "@rollno"/></td>
<td><xsl:value-of select = "firstname"/></td>
<td><xsl:value-of select = "lastname"/></td>
<td><xsl:value-of select = "marks"/></td>
<td>
<xsl:choose>
<xsl:when test = "marks >= 70">
Distinction
</xsl:when>