【发布时间】:2018-05-10 03:20:40
【问题描述】:
我是使用 xml 和 xslt 的绝对初学者。
我有一个 xml 文档和一个 xslt 文档,但由于某种原因,我无法让它在浏览器(Internet Explorer)中正确显示。
如果您能深入了解为什么会发生这种情况,我们将不胜感激。它与命名空间有关吗?我有一个命名空间,但我看到的示例实际上并未在其 xml 文档中包含命名空间。这是我能想到的唯一会引起问题的事情。
谢谢。
这是我的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="D:\menu.xsl" ?>
<menu xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.wasabi.com/pakistan/menu"
xsi:schemaLocation="http://www.wasabi.com/pakistan/menu file:///D:/XML/schemas/menuSchema.xsd" > <!--Tells the document where to find the associated schema-->
<menuItem>
<name>chicken</name>
<price>$9.99</price>
<image>
<img src="chiccken.png"/>
</image>
<description>
<!--Just some flavor text -->
<![CDATA[
hello there blah.
]]>
</description>
<calories>
<calorieCount> 1200 </calorieCount> <!--set as integer -->
</calories>
<icon/>
</menuItem>
<menuItem>
<name>turkey</name>
<price>$4.99</price>
<image>
<img src="turkey.png"/>
</image>
<description>
<![CDATA[
lorem ipsum ...
]]>
</description>
<calories>
<calorieCount> 500 </calorieCount>
</calories>
<icon iconName="Sodium">♦</icon><!--Character reference that tells customer that means the dish is low in sodium -->
</menuItem>
这是我的 XSL:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<xsl:template match="/">
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
document.title =
(location.pathname.substring(location.pathname.lastIndexOf("/") +
1)).replace('.xml','');
});
</script>
<title> </title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="menuItem">
<p>
<xsl:apply-templates select="name"/>
<xsl:apply-templates select="price"/>
</p>
</xsl:template>
<xsl:template match="name">
Name: <span style="color:#ff0000">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
<xsl:template match="price">
Price: <span style="color:#ff0000">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
</xsl:stylesheet>
【问题讨论】: