【发布时间】:2014-04-30 08:09:18
【问题描述】:
我必须为下面的 xml 标记编写 XSL 样式表。
<?xml version = "1.0"?>
<?xml-stylesheet type = ""text/xsl" href = "cookies.xsl"?>
<product name="Grandma White's Cookies">
<servingsize>1 package</servingsize>
<calories>
<total>260 Calories</total>
<fat>100 Calories</fat>
</calories>
<fat>
<total>11 grams</total>
<saturated>2 grams</saturated>
</fat>
<cholesterol>
5 milligrams</cholesterol>
<sodium>
210 milligrams</sodium>
<carbohydrates>
<total>36 grams</tota`enter code here`l>
<fiber>2 grams</fiber>
<sugars>15 grams</sugars>
</carbohydrates>
<protein>5 grams</protein>
</product>
我的 xsl 标记如下。我需要以表格形式显示信息。我尝试在下面输出信息,但没有显示出来。你能帮我弄清楚吗?
<?xml version = "1.0"?>
<xsl:stylesheet version ="1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:output method = "html" doctype-system = "about:legacy-compat" />
<xsl:template match = "/">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta charset = "utf-8" />
<link rel = "stylesheet" type = "text/css" href ="style.css" />
<title>Grandma White's cookies</title>
</head>
<body>
<h1>
Grandma White's cookie nutrition facts </h1>
<h3>Serving size <xsl:value-of select="servingsize"/></h3>
<table>
<thead>
<tr>
<th>Description></th>
<th>Information</th>
</tr>
</thead>
<xsl:for-each select="/calories">
<tr>
<td>Calories</td>
<td><xsl:for-each select="total"/><br></br>
<xsl:for-each select="fat"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
【问题讨论】:
-
检查'total'标签,你在stackoverflow上留下了评论!
-
请发布您想要实现的输出。