Reputation: 49
I'm a beginner in XML. I use the book "XML: Visual Quickstart Guide" by Kevin Howard Goldberg. I've just learned how to transform XML files with XSLT. Everything you will see in my code is what I've learned until now about XML and XSLT.
I wanted to make an HTML table with the XML data in it, like this:
http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog
but it only shows me the data in a row without rendering the HTML tags:
https://i.sstatic.net/QLECw.jpg
So why is my code not working?
This is my XML code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet content-type="application/xml" href="page2_xslt.xsl"?>
<favNumbers>
<song>
<title>Song 1</title>
<artist>Artist 1</artist>
</song>
<song>
<title>Song 2</title>
<artist>Artist 2</artist>
</song>
<song>
<title>Song 3</title>
<artist>Artist 3</artist>
</song>
<song>
<title>Song 4</title>
<artist>Artist 4</artist>
</song>
</favNumbers>
This is my XSLT code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/">
<html>
<head>
<title>Favorite Songs</title>
</head>
<body>
<table>
<tr>
<th>Favorite Songs</th>
</tr>
<tr>
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="favNumbers/song">
<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>
It's becoming really frustrating now. Did I miss a quote, a comma or anything else? Or is it something much more complex. I've searched for an answer on many sites, but I couldn't find one, maybe because English is not my first language. So please help me out.
Thank you :)
Upvotes: 0
Views: 1297
Reputation: 117165
Try changing this part in your XML:
<?xml-stylesheet content-type="application/xml" href="page2_xslt.xsl"?>
to:
<?xml-stylesheet type="text/xsl" href="page2_xslt.xsl"?>
Upvotes: 1