我有以下帶有嵌入式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文檔中的正確位置,現在是問題。 –