大家早上好,我有这个xml页面,但没有在浏览器上显示,你能告诉我为什么吗?我真的试图找出原因,但我没有实现它,这里是文件代码:
XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="shakes.xsl"?>
<!DOCTYPE shakes
[
<!ELEMENT shake (name,short_desc,link_desc,price)
<!ELEMENT name (#PCDATA)>
<!ELEMENT link_desc (#PCDATA)>
<!ELEMENT price (#PCDATA)>
]>
<shakes>
<shake>
<name number="1">FruitStorm</name>
<short_desc>orange,pineapple,lemon</short_desc>
<link_desc>about</link_desc>
<price>$1.80</price>
</shake>
<shake>
<name number="2">RevivalShake</name>
<short_desc>honey,apple,wildfruits</short_desc>
<link_desc>about</link_desc>
<price>$2.00</price>
</shake>
<shake number="3">
<name>ShakeStyle</name>
<short_desc>carrots,greenroot,tomatoe,lemon</short_desc>
<link_desc>about</link_desc>
<price>$1.80</price>
</shake>
</shakes>
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="shakes">
<html>
<head>
<link rel="stylesheet" type="text/css" href="cssData.css">
</head>
<body>
<xsl:apply-templates select="shakes"/>
</body>
</html>
<xsl:template>
<xsl:template match="shake">
<div class="Outer_ShakeFrame">
<span class="Text_ShakeFrame" width="80%"><xsl:value-of select="name"></span>
<span class="Text_ShakeFrame" width="20%"><xsl:value-of select="@number"></span>
<div class="Inner_ShakeFrame"></div>
<span class="Price_ShakeFrame"><xsl:value-of select="price"></span>
<marquee class="Marquee_ShakeFrame" scrollamount="4"><xsl:value-of select="short_desc"></marquee>
<a href="vide"><img src="arrow.gif" alt="About" class="Link_ShakeFrame"></a>
</div>
</xsl:template>
</xsl:stylesheet>
CSS
.Outer_ShakeFrame{
display:block;
border:1px solid black;
padding:2px;
margin:2px;
width:116px;
height:165px;
}
.Text_ShakeFrame{
text-transform:uppercase;
border-color:#000000;
padding:3px;
background-color:lightblue;
font-size:0.8em;
}
.Inner_ShakeFrame{
display:block;
border:1px solid black;
padding:5px;
margin-left:2.5px;
margin-top:7px;
width:85%;
height:85px;
}
.Link_ShakeFrame{
width:20%;
height:1.4em;
}
.Marquee_ShakeFrame{
background-color:lightblue;
width:70%;
padding:3px;
font-size:0.8em;
text-transform:uppercase;
margin-top:3px;
}
.Price_ShakeFrame{
text-align:right;
font-size:0.8em;
background-color:lightblue;
text-transform:uppercase;
}
它应该显示三个项目(见图),其中的信息是从xml文件中提取的xls文件。先感谢您 enter image description here
答案 0 :(得分:0)
您的 xsl 文件中出现错误。您没有关闭<xsl:template match="shakes">
代码,而是重新打开并清空模板标签[缺少斜线/在那里]。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="shakes">
<html>
<head>
<link rel="stylesheet" type="text/css" href="cssData.css" /> // You are missing closing slash here
</head>
<body>
<xsl:apply-templates select="shakes"/>
</body>
</html>
</xsl:template> // You are missing closing slash here
<xsl:template match="shake">
<div class="Outer_ShakeFrame">
<span class="Text_ShakeFrame" width="80%"><xsl:value-of select="name"></span>
<span class="Text_ShakeFrame" width="20%"><xsl:value-of select="@number"></span>
<div class="Inner_ShakeFrame"></div>
<span class="Price_ShakeFrame"><xsl:value-of select="price"></span>
<marquee class="Marquee_ShakeFrame" scrollamount="4"><xsl:value-of select="short_desc"></marquee>
<a href="vide"><img src="arrow.gif" alt="About" class="Link_ShakeFrame"></a>
</div>
</xsl:template>
</xsl:stylesheet>