I have an XML file (dynamically created) and an XSL style sheet; if I open the XML file within Firefox, I get a nice table of output.
However, I want to render this data within an HTML page. I’ve tried using:
HTML file:
<html>
<body>
<xml src="test_data.xml">
</xml>
</body>
</html>
But I can’t get anything to render. Both my XML file and my XSL file are in the same directory.
I’ve tried removing <html> and <body> from my XSL output, but still get no results.
Online I’ve read that some methods differ for IE and Firefox; how can I render an XML file within an HTML page in Firefox?
XML file (test_data.xml):
<?xml-stylesheet type="text/xsl" href="report_proteins.xsl"?>
<group_list>
<protein_group>
<protein name="A_1" />
<protein name="A_2" />
</protein_group>
<protein_group>
<protein name="B_1" />
</protein_group>
<protein_group>
<protein name="C_1" />
<protein name="C_2" />
<protein name="C_3" />
</protein_group>
</group_list>
XSL file (report_proteins.xsl):
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>MAP proteins</h2>
<table border="0">
<tr>
<th bgcolor="#E7FFCC">Group number</th>
<th bgcolor="#D2FBFF">Proteins</th>
</tr>
<xsl:for-each select="group_list/protein_group">
<tr>
<td>
<xsl:number />
</td>
<td>
<xsl:for-each select="protein">
<xsl:value-of select="@name"/><xsl:text> </xsl:text>
</xsl:for-each>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
There is no such
xmlnode in HTML, so that is the reason why it doesn’t work. You don’t need the HTML file at all. Your XSLT sheet generates a full XHTML document, and the browser should be able to render that as it is if you open the XML find in the browser.You should add the XHTML namespace to the XSLT stylesheet.