Generating XSL from XML
Hi All,
I have the following XMl file
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<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>The very best of</title>
<artist>Cat Stevens</artist>
<country>UK</country>
<company>Island</company>
<price>8.90</price>
<year>1990</year>
</cd>
<cd>
<title>The very best of</title>
<artist>Joe Cocker</artist>
<country>USA</country>
<company>EMI</company>
<price>8.20</price>
<year>1987</year>
</cd>
</catalog>
I have to generate the XSL file to diplay data in HTML , where data out oput should display the title name followed by list of all the artist names with comma seperated .
I have written the following code..
<?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>
<xsl:for-each select="catalog/cd">
<xsl:value-of select="title"/>
<xsl><b> : </b> </xsl>
<xsl:value-of select="artist"/>
<xsl:if test="position() != last()"> <b> , </b></xsl:if>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
which will give result as
Empire Burlesque : Bob Dylan , Hide your heart : Bonnie Tyler , The very best of : Cat Stevens , The very best of : Joe Cocker
But I want result as
Empire Burlesque : Bob Dylan , Hide your heart : Bonnie Tyler , The very best of : Cat Stevens , Joe Cocker
someone please help me , by providing the suggestion to resolve this.
Thanks in advance
|