简体   繁体   English

我正在尝试创建XML和XSL,但它给我一个错误,我不知道该怎么办

[英]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: 本质上,您只需要更改两件事:

  • Change the output method in <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.

相关问题 我无法弄清楚错误是什么,错误:未捕获的 ReferenceError - I can't figure out what the error is, Error: Uncaught ReferenceError 我正在尝试制作HSV颜色选择器,但是我不知道如何生成重叠图像 - I am trying to make an HSV color picker but I can't figure out how to generate the overlay image 我正在尝试找出此Javascript代码出了什么问题 - I am trying to figure out what is wrong with this Javascript code 我想弄清楚这里出了什么问题 - I am trying to figure out what is wrong here 我想弄清楚下面的 javascript 以及它的作用 - I am trying to figure out below javascript and what it does 我正在尝试做这个问题,但是 state 给我带来了问题 - I am trying to do this question but, state is giving me problems 我是 nodejs 的新手,我收到了参考错误:io is not defined ,我想不通 - I am new to nodejs and I'm getting reference error: io is not defined ,I can't figure it out 我正在尝试导出一个函数以导入到另一个 javascript 页面,但无法弄清楚如何使用导出/导入来做到这一点 - i am trying to export a function to import into another javascript page but can not figure out how to do it with exports/imports 我不知道为什么我收到以下错误“错误:元素类型无效:” - I can't figure out why I am getting the following error "Error: Element type is invalid:" 循环学习。 无法弄清楚我的代码中缺少什么。 - Learning While Loops. Can't figure out what I am missing in my code.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM