[英]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
I am trying to create a xml file linked to xsl and whenever I run it, any browser I use says the same error. 我试图创建一个链接到xsl的xml文件,每当我运行它时,我使用的任何浏览器都会说同样的错误。 I have tried researching what to do but I still don't get it.
我已经尝试研究该怎么做,但仍然不了解。 I saw something about security and permission but I tried and still got the same result.
我看到了一些有关安全性和权限的信息,但是我尝试了一下,但仍然得到了相同的结果。
Can anyone please help? 谁能帮忙吗? I am new with XML working with HTML learning through a book.
我是XML的新手,可以通过一本书学习HTML。 I could not find anything that will help me and really want to see what I am doing wrong or what the work around will be at this point.
我找不到任何对我有帮助的东西,并且真的想看看我做错了什么,或者此时的解决方法是什么。 Thank you in advance!!
先感谢您!!
XML: 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>
My XSLT so far: 到目前为止,我的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>
Essentially, you only have to change two things: 本质上,您只需要更改两件事:
<xsl:output...
to <xsl:output method="html" version="1.0" ...
<xsl:output...
的输出方法更改为<xsl:output method="html" version="1.0" ...
And change the <xsl:for-each...
to 并将
<xsl:for-each...
更改为
<xsl:for-each select="/myProducts/product">
because the /chapter10XML
root element is not present in the XML. 因为
/chapter10XML
根元素不在XML中。
Now you get an HTML output that can be rendered in a browser. 现在,您可以获得可以在浏览器中呈现的HTML输出。
If you get a security error, you're probably using Chrome as a browser, which has tight restrictions on executing local files. 如果遇到安全错误,则可能是将Chrome用作浏览器,该浏览器对执行本地文件有严格的限制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.