我有以下带有嵌入式XSLT的XML文件。XML:无法使用嵌入式XSLT
<?xml version="1.0" encoding="UTF-8"?>
<doc>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id = "style1">
<xsl:import href = "S1000D_compare.xsl"/>
<xsl:output method="html"/>
</xsl:stylesheet>
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>Two of our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>Berry-Berry Belgian Waffles</name>
<price>$8.95</price>
<description>Belgian waffles covered with assorted fresh berries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>French Toast</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
<calories>950</calories>
</food>
</breakfast_menu>
</doc>
该导入的样式表具有以下内容:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select = "breakfast_menu/food">
<p>Food: <xsl:value-of select = "name"/></p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
在Chrome和IE,它打开作为一个文件树,而不是将所述变换和显示HTML结果。
我添加了基于this question的“doc”根元素。我没有错误地通过an online validator运行文档。
'xsl:import'和'xsl:output'元素在放置它们的位置没有意义 - 它们属于'xsl:stylesheet'元素的子元素。我不确定修复这个问题是否能够真正解决您的问题,但这将是迈向正确方向的一步。 –
请注意,现在,'xsl:import'和'xsl:output'元素没有'xsl'命名空间前缀的范围内声明,因此即使它们在该位置有意义,他们并不意味着你可能期望他们的意思。 –
谢谢!这些是复制粘贴错误。 (我开始写下我的问题,根据类似的问题尝试了一些东西,然后将更新粘贴到错误的位置。)他们在我的XML文档中的正确位置,现在是问题。 –