XSL style sheet programming


To write a program using xsl style sheet.



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




<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


–             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”?>



<title>Empire Burlesque</title>

<artist>Bob Dylan</artist>







<title>Hide your heart</title>

<artist>Bonnie Tyler</artist>


<company>CBS Records</company>





<title>Greatest Hits</title>

<artist>Dolly Parton</artist>







<title>Still got the blues</title>

<artist>Gary Moore</artist>


<company>Virgin records</company>






<artist>Eros Ramazzotti</artist>







<title>One night only</title>

<artist>Bee Gees</artist>








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=”/”>



<h2>My CD Collection</h2>

<table border=”1″>

<tr bgcolor=”#9acd32″>




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


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

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