加载 XML 文件时没有数据显示。似乎没有使用 XSL 文件,我只是得到一个空白屏幕。请有人看看,看看它为什么会这样做。提前致谢。
这是我的代码:
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>
</computers>
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>