XSL
tags :
Summary #
XSL is a language that can transform XML into XHTML, a language that can filter and sort XML data, a language that can define parts of a XML document, a language that can format XML data based on the data value, like displaying negative numbers in red, and a language that can output XML data to different devices, like screen, paper, or voice.
cdcatalog.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<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>Happy Birthday</title>
<artist>Weird Al Yankovic</artist>
<country>USA</country>
<company>Scotti Brothers</company>
<price>0.99</price>
<year>1983</year>
</cd>
</catalog>
cdcatalog.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<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>
<tr>
<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>
Link xsl style sheet to XML document.
<?xml version="1.0" encoding="ISO-8859-1"?>
<?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>Happy Birthday</title>
<artist>Weird Al Yankovic</artist>
<country>USA</country>
<company>Scotti Brothers</company>
<price>0.99</price>
<year>1983</year>
</cd>
</catalog>
If you have an XSL compliant browser it will transform your XML into XHTML.