继续收到以下错误:
“此XML文件似乎没有与之关联的任何样式信息。文档树如下所示。”
继承我的代码:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl href="computers.xsl"?>
<!DOCTYPE computers SYSTEM "computers.dtd">
<computers>
<computer>
<cpu ghz="3.5" unlocked="Yes">Intel i7 3770k</cpu>
<motherboard>MSI M-Power</motherboard>
<ram>8</ram>
<storage>
<hdd>1000</hdd>
<ssd>128</ssd>
</storage>
<gpu group="ATI">7950</gpu>
<psu>750</psu>
</computer>
<computer>
<cpu ghz="3.5" unlocked="Yes">Intel i5 3570k</cpu>
<motherboard>ASRock Extreme 4</motherboard>
<ram>8</ram>
<storage>
<hdd>1000</hdd>
</storage>
<gpu group="ATI">7870</gpu>
<psu>600</psu>
</computer>
<computer>
<cpu ghz="3.5" unlocked="No">Intel i5 3550</cpu>
<motherboard>ASRock Extreme 3</motherboard>
<ram>8</ram>
<storage>
<hdd>500</hdd>
</storage>
<gpu group="GeForce">9600GT</gpu>
<psu>500</psu>
</computer>
DTD:
<!ELEMENT computer (cpu,motherboard,ram,storage,gpu,psu) >
<!ELEMENT cpu (#PCDATA)>
<!ELEMENT motherboard (#PCDATA)>
<!ELEMENT ram (#PCDATA)>
<!ELEMENT storage(hdd,ssd*)>
<!ELEMENT hdd (#PCDATA)>
<!ELEMENT ssd (#PCDATA)>
<!ELEMENT gpu (#PCDATA)>
<!ELEMENT psu (#PCDATA)>
<!ATLIST cpu
ghz CDATA #REQUIRED>
unlocked (Yes|No) "No">
<!ATLIST gpu
group (ATI|GeForce) "ATI">
XSL:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>HELLO WORLD</title>
</head>
<body>
<xsl:for-each select="computers/computer">
<table border="1">
<tr>
<td>
<xsl:value-of select="cpu"/>
</td>
<td>
<xsl:value-of select="cpu/@ghz"/>
</td>
<td>
<xsl:value-of select="cpu/@unlocked"/>
</td>
</tr>
<tr>
<td>
<xsl:value-of select="motherboard"/>
</td>
</tr>
<tr>
<td>
<xsl:value-of select="ram"/>
</td>
</tr>
<tr>
<td>
<xsl:for-each select="storage"/>
<xsl:value-of select="hdd"/>
<xsl:value-of select="ssd"/>
</xsl:for-each>
</td>
</tr>
<tr>
<td>
<xsl:value-of select="gpu"/>
</td>
</tr>
<tr>
<td>
<xsl:value-of select="psu"/>
</td>
</tr>
</table>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
请有人帮我弄清楚它有什么问题。提前谢谢。
答案 0 :(得分:0)
该行
<?xml-stylesheet type="text/xsl href="computers.xsl"?>
应该是
<?xml-stylesheet type="text/xsl" href="computers.xsl"?>