XSL style sheet programming

AIM:

To write a program using xsl style sheet.

 

XSL:

<xsl:style sheet xmlns:xsl=”http://www.w3.org/TB/wd-xsl”>

 

XSL CONSTRUCTS:

 

<XSL:VALUE-OF>                –          To insert the value of the element .

<XSL:IF>                                 –          To perform the conditional matching.

<XSL:FOR-EACH>                –          To establish a loop through a select element in the document.

<XSL:APPLY TEMPLATE>- To apply template in a style sheet.

–              xsl document may have one or more templates

–         Which describe the pattern which is used to match the xml

element.

–             xsl template element has the attribute called match, to match

the pattern in the xml document.

 

FILE NAME: cd.html:

FILE NAME: Cdcatalog.xml:

 

<?xml version=”1.0″ encoding=”ISO-8859-1″?>

<!– Edited by XMLSpy® –>

<?xml-stylesheet type=”text/xsl” href=”cdcatalog.xsl”?>

<catalog>

<cd>

<title>Empire Burlesque</title>

<artist>Bob Dylan</artist>

<country>USA</country>

<company>Columbia</company>

<price>10.90</price>

<year>1985</year>

</cd>

<cd>

<title>Hide your heart</title>

<artist>Bonnie Tyler</artist>

<country>UK</country>

<company>CBS Records</company>

<price>9.90</price>

<year>1988</year>

</cd>

<cd>

<title>Greatest Hits</title>

<artist>Dolly Parton</artist>

<country>USA</country>

<company>RCA</company>

<price>9.90</price>

<year>1982</year>

</cd>

<cd>

<title>Still got the blues</title>

<artist>Gary Moore</artist>

<country>UK</country>

<company>Virgin records</company>

<price>10.20</price>

<year>1990</year>

</cd>

<cd>

<title>Eros</title>

<artist>Eros Ramazzotti</artist>

<country>EU</country>

<company>BMG</company>

<price>9.90</price>

<year>1997</year>

</cd>

<cd>

<title>One night only</title>

<artist>Bee Gees</artist>

<country>UK</country>

<company>Polydor</company>

<price>10.90</price>

<year>1998</year>

</cd>

</catalog>

 

FILE NAME: Cdcatalog.xsl:

 

<?xml version=”1.0″ encoding=”ISO-8859-1″?>

<!– Edited by XMLSpy® –>

<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>

 

<xsl:template match=”/”>

<html>

<body>

<h2>My CD Collection</h2>

<table border=”1″>

<tr bgcolor=”#9acd32″>

<th>Title</th>

<th>Artist</th>

</tr>

<xsl:for-each select=”catalog/cd”>

<tr>

<td><xsl:value-of select=”title”/></td>

<td><xsl:value-of select=”artist”/></td>

</tr>

</xsl:for-each>

</table>

</body>

</html>

</xsl:template>

</xsl:stylesheet>