我正在尝试创建一个链接到xsl的xml文件,每当我运行它时,我使用的任何浏览器都会显示相同的错误。我试过研究该怎么做,但我还是不明白。我看到了一些关于安全性和权限的东西,但我尝试了一下,仍然得到了同样的结果。
有人能帮帮忙吗?我是一个新手,通过一本书学习XML和HTML。我找不到任何对我有帮助的东西,我真的想看看我做错了什么,或者在这一点上应该做些什么。提前谢谢你!!
XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="chapter10XML.xsl"?>
<!DOCTYPE myProducts [
<!ELEMENT myProducts (product)>
<!ELEMENT product (prodName, prodImg, description, price, stockLevel, sku)>
]>
<myProducts>
<product id = "i7-8">
<prodName>I7 8th Generation</prodName>
<prodImg>/images.i7-8thgen.jpg</prodImg>
<description>Core i7-8700K can reach a frequency of 4.7GHz. These chips
can be expanded with up to 40 platform PCIe 3.0 lanes.</description>
<price>$300.00</price>
<stockLevel>25</stockLevel>
<sku>INT-78</sku>
</product>
<product id = "i5-8">
<prodName>I5 8th Generation</prodName>
<prodImg>/images.i5-8thgen.jpg</prodImg>
<description>Intel Core i5-8400 comes with 6 processing Cores and 6
Threads.</description>
<price>$250.00</price>
<stockLevel>20</stockLevel>
<sku>INT-58</sku>
</product>
<product id = "i3-8">
<prodName>I3 8th Generation</prodName>
<prodImg>/images.i3-8thgen.jpg</prodImg>
<description>Intel Core i3 comes with 4 processing Cores and 4 Threads.
</description>
<price>$200.00</price>
<stockLevel>20</stockLevel>
<sku>INT-38</sku>
</product>
<product id = "i5-7">
<prodName>I5 7th Generation</prodName>
<prodImg>/images.i5-7thgen.jpg</prodImg>
<description>64-bit dual-core mid-range performance x86 mobile
microprocessor introduced by Intel in mid-2016.</description>
<price>$170.00</price>
<stockLevel>20</stockLevel>
<sku>INT-57</sku>
</product>
<product id = "i3-7">
<prodName>I3 7th Generation</prodName>
<prodImg>/images.i3-7thgen.jpg</prodImg>
<description>Core i3-7100U is a 64-bit dual-core low-end performance x86
mobile microprocessor introduced by Intel in mid-2016.</description>
<price>$170.00</price>
<stockLevel>20</stockLevel>
<sku>INT-37</sku>
</product>
</myProducts>到目前为止我的XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<title>Chapter 10 XML</title>
</head>
<body>
<div class="container">
<xsl:for-each select="/chapter10XML/myProducts/product">
<div class="product">
<h3>
<xsl:value-of select="@id"/>
</h3>
<p>
<xsl:value-of select="price"/>
</p>
<p>
<img src="[prodImg]"/>
</p>
<p>
<xsl:value-of select="description"/>
</p>
<p>In Stock: <xsl.value-of select="stocklevel"/></p>
<p>
<xsl:value-of select="sku"/>
</p>
</div>
</xsl:for-each>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>发布于 2018-12-07 11:45:49
从本质上讲,你只需要改变两件事:
将<xsl:output method="html" version="1.0" ...
<xsl:output...中的输出方法更改为<xsl:for-each...因为XML.中不存在/chapter10XML根元素
现在,您将获得一个可以在浏览器中呈现的HTML输出。
如果你得到一个安全错误,你可能正在使用Chrome作为浏览器,它对执行本地文件有严格的限制。
https://stackoverflow.com/questions/53662793
复制相似问题