Reputation: 178
I am trying to link my XSL to my XML however when I load the XML page in Chrome or other web browsers I get a blank page.
I'm not sure exactly what is going wrong wit it.
Below is my XML
<?xml-stylesheet type="text/xsl" href="vaults.xsl"?>
<vaults xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vaults.xsd">
<vault>
<vaultname>Los Angeles Vault </vaultname>
<state>California</state>
<location>Los Angeles (Cathedral)</location>
<description>The Vault-Tec demonstration vault. It was not part of the experiment, and was the Master's vault under the Cathedral. </description>
<fate> </fate>
<appearance>Fallout</appearance>
</vault>
</vaults>
The following the is XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Vaults</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">vault</th>
</tr>
<xsl:for-each select="vaults/vault">
<tr>
<td><xsl:value-of select="vaultname" /></td>
<td><xsl:value-of select="state" /></td>
<td><xsl:value-of select="location" /></td>
<td><xsl:value-of select="description" /></td>
<td><xsl:value-of select="fate" /></td>
<td><xsl:value-of select="appearance" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Upvotes: 2
Views: 1051
Reputation: 57189
however when I load the XML page in Chrome or other web browsers I get a blank page.
If you load it from the local disk in Chrome, you will get a blank page, same in Internet Explorer. This is for security reasons.
I tested your XML and XSLT, stored both files locally and opened it in Firefox, and it "just worked":
Note, I would suggest making your stylesheet a bit easier to read and maintain. I.e., something along those lines (typically, using xsl:apply-templates
with matching templates is easier to maintain and is better guarded against changes in the input):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Vaults</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">vault</th>
</tr>
<xsl:apply-templates select="vaults/vault" />
</table>
</body>
</html>
</xsl:template>
<xsl:template match="vault">
<tr>
<xsl:apply-templates select="*" />
</tr>
</xsl:template>
<xsl:template match="*[parent::vault]">
<td><xsl:value-of select="." /></td>
</xsl:template>
</xsl:stylesheet>
Upvotes: 3