首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我试图创建一个XML和XSL,但是它给了我一个错误,我不知道该怎么做

我试图创建一个XML和XSL,但是它给了我一个错误,我不知道该怎么做
EN

Stack Overflow用户
提问于 2018-12-07 11:28:05
回答 1查看 124关注 0票数 0

我正在尝试创建一个链接到xsl的xml文件,每当我运行它时,我使用的任何浏览器都会显示相同的错误。我试过研究该怎么做,但我还是不明白。我看到了一些关于安全性和权限的东西,但我尝试了一下,仍然得到了同样的结果。

有人能帮帮忙吗?我是一个新手,通过一本书学习XML和HTML。我找不到任何对我有帮助的东西,我真的想看看我做错了什么,或者在这一点上应该做些什么。提前谢谢你!!

XML:

代码语言:javascript
复制
 <?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:

代码语言:javascript
复制
<?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>
EN

回答 1

Stack Overflow用户

发布于 2018-12-07 11:45:49

从本质上讲,你只需要改变两件事:

<xsl:output method="html" version="1.0" ...

  • And更改为
  • <xsl:output...中的输出方法更改为<xsl:for-each...

因为XML.中不存在/chapter10XML根元素

现在,您将获得一个可以在浏览器中呈现的HTML输出。

如果你得到一个安全错误,你可能正在使用Chrome作为浏览器,它对执行本地文件有严格的限制。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53662793

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档