[英]I can't figure out what the error is, Error: Uncaught ReferenceError
[英]I am trying to create an XML and XSL, but it is giving me an error that I can't figure out what to do
我試圖創建一個鏈接到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>
本質上,您只需要更改兩件事:
<xsl:output...
的輸出方法更改為<xsl:output method="html" version="1.0" ...
並將<xsl:for-each...
更改為
<xsl:for-each select="/myProducts/product">
因為/chapter10XML
根元素不在XML中。
現在,您可以獲得可以在瀏覽器中呈現的HTML輸出。
如果遇到安全錯誤,則可能是將Chrome用作瀏覽器,該瀏覽器對執行本地文件有嚴格的限制。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.