我有一个奇怪的problem.XSL不工作的xml.This是我的xml和xsl代码:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xsl-stylesheet type= "text/xsl" href= "w3c.xsl"?>
<catalog>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
<cd>
<title>Eros</title>
<artist>Eros Ramazzotti</artist>
<country>EU</country>
<company>BMG</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>Romanza</title>
<artist>Andrea Bocelli</artist>
<country>EU</country>
<company>Polydor</company>
<price>10.80</price>
<year>1996</year>
</cd>
</catalog>这是我的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 xmlns="http://www.w3.org/1999/xhtml">
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<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>注意:
我从W3C上获取了这段代码,因此它是一个可以工作的代码。我在谷歌上搜索了很多,但找不到任何有效的解决方案。我使用了ie、firefox和chrome在它们中的任何一个上都不能工作。我在我的远程服务器上测试过它不工作either.The错误是“这个XML文件似乎没有任何与之相关的样式信息。文档树如下所示。“occurs.In href同样的错误我已经尝试了从完整路径到文件名的所有可能的链接。我也尝试了chrome的--.The- file -access-occurs.In-files,但work.Please不能帮助我解决这个问题。
发布于 2012-08-28 21:42:15
请注意,XML文件的第二行写着:
<?xsl-stylesheet type= "text/xsl" href= "w3c.xls"?>注意到w3c.xls (而不是xsl ?)你的文件名是什么?注意,is是xml-stylesheet,而不是xsl-stylesheet。
所以这应该可以做到:
<?xml-stylesheet type= "text/xsl" href= "w3c.xsl"?>发布于 2012-08-28 21:55:01
我不能重现这个问题。
当提供的XSLT样式表:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<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>对提供的XML文档应用了(我拥有的所有9种不同的XSLT处理器)。
<catalog>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
<cd>
<title>Eros</title>
<artist>Eros Ramazzotti</artist>
<country>EU</country>
<company>BMG</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>Romanza</title>
<artist>Andrea Bocelli</artist>
<country>EU</country>
<company>Polydor</company>
<price>10.80</price>
<year>1996</year>
</cd>
</catalog>生成了正确的结果
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td>Greatest Hits</td>
<td>Dolly Parton</td>
</tr>
<tr>
<td>Eros</td>
<td>Eros Ramazzotti</td>
</tr>
<tr>
<td>Romanza</td>
<td>Andrea Bocelli</td>
</tr>
</table>
</body>
</html>https://stackoverflow.com/questions/12160515
复制相似问题