我对XML很新,我有一个文件,我希望在网络浏览器中显示,但除非我在xsl
文件中删除xml
声明,否则不显示任何内容。有人能告诉我如何解决这个问题吗?谢谢
XML
档案
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="XXXXX.xsl"?>
<cookie>
<name>Grandma White's Cookies</name>
<serving_size>
<quantity>1</quantity>
<unit_of_measurement>package</unit_of_measurement>
</serving_size>
<calories>
<quantity>260</quantity>
<unit_of_measurement>Calories</unit_of_measurement>
</calories>
<fat_calories>
<quantity>100</quantity>
<unit_of_measurement>Calories</unit_of_measurement>
</fat_calories>
<fat>
<quantity>11</quantity>
<unit_of_measurement>grams</unit_of_measurement>
</fat>
<saturated_fat>
<quantity>2</quantity>
<unit_of_measurement>Calories</unit_of_measurement>
</saturated_fat>
<cholesterol>
<quantity>5</quantity>
<unit_of_measurement>milligrams</unit_of_measurement>
</cholesterol>
<sodium>
<quantity>210</quantity>
<unit_of_measurement>milligrams</unit_of_measurement>
</sodium>
<protein>
<quantity>5</quantity>
<unit_of_measurement>grams</unit_of_measurement>
</protein>
<carbohydrates>
<quantity>36</quantity>
<unit_of_measurement>grams</unit_of_measurement>
</carbohydrates>
<sugar>
<quantity>15</quantity>
<unit_of_measurement>grams</unit_of_measurement>
</sugar>
<fiber>
<quantity>2</quantity>
<unit_of_measurement>grams</unit_of_measurement>
</fiber>
</cookie>
XSL
档案
<?xml version="1.0" encoding="UTF-8"?>
<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>
<head>
<title><xsl:value-of select = "name" /></title>
</head>
<body>
<table border = "1px solid black" >
<thead>
<tr>
<th colspan = "3"><xsl:value-of select = "name" /></th>
</tr>
</thead>
<tbody>
<tr>
<th>Serving Size</th>
<th><xsl:value-of select = "serving_size/quantity" /></th>
<th><xsl:value-of select = "serving_size/unit_of_measurement" /></th>
</tr>
<tr>
<th>Calories</th>
<th><xsl:value-of select = "calories/quantity" /></th>
<th><xsl:value-of select = "calories/unit_of_measurement" /></th>
</tr>
<tr>
<th>Fat Calories</th>
<th><xsl:value-of select = "fat_calories/quantity" /></th>
<th><xsl:value-of select = "fat_calories/unit_of_measurement" /></th>
</tr>
<tr>
<th>Fat</th>
<th><xsl:value-of select = "fat/quantity" /></th>
<th><xsl:value-of select = "fat/unit_of_measurement" /></th>
</tr>
<tr>
<th>Saturated Fat</th>
<th><xsl:value-of select = "saturated_fat/quantity" /></th>
<th><xsl:value-of select = "saturated_fat/unit_of_measurement" /></th>
</tr>
<tr>
<th>Carbohydrate</th>
<th><xsl:value-of select = "carbohydrates/quantity" /></th>
<th><xsl:value-of select = "carbohydrates/unit_of_measurement" /></th>
</tr>
<tr>
<th>Cholesterol</th>
<th><xsl:value-of select = "cholesterol/quantity" /></th>
<th><xsl:value-of select = "cholesterol/unit_of_measurement"/></th>
</tr>
<tr>
<th>Sugar</th>
<th><xsl:value-of select = "sugars/quantity" /><xsl:text> </xsl:text></th>
<th><xsl:value-of select = "sugar/unit_of_measurement" /></th>
</tr>
<tr>
<th>Protein</th>
<th><xsl:value-of select = "protein/quantity" /></th>
<th><xsl:value-of select = "protein/unit_of_measurement" /></th>
</tr>
<tr>
<th>Sodium</th>
<th><xsl:value-of select = "sodium/quantity" /></th>
<th><xsl:value-of select = "sodium/unit_of_measurement" /></th>
</tr>
<tr>
<th>fiber</th>
<th><xsl:value-of select = "fiber/quantity" /><xsl:text> </xsl:text></th>
<th><xsl:value-of select = "serving_size/unit_of_measurement" /></th>
</tr>
</tbody>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>