Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将XSL样式表连接到XML文件以生成HTML?_Html_Xml_Xslt - Fatal编程技术网

如何将XSL样式表连接到XML文件以生成HTML?

如何将XSL样式表连接到XML文件以生成HTML?,html,xml,xslt,Html,Xml,Xslt,一个多星期以来,我一直在想如何做到这一点,但似乎没有任何效果。我已经确定我也引用了XML中的XSL文件,我不确定我做错了什么,但是我非常感谢了解这种语法的人的帮助。我是XML新手,所以大家放松点 以下是我目前的代码: XML <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet href="Question2.xsl" type="text/xsl" ?> <!DOCTYPE patronRecord [

一个多星期以来,我一直在想如何做到这一点,但似乎没有任何效果。我已经确定我也引用了XML中的XSL文件,我不确定我做错了什么,但是我非常感谢了解这种语法的人的帮助。我是XML新手,所以大家放松点

以下是我目前的代码:

XML

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="Question2.xsl" type="text/xsl" ?>
<!DOCTYPE patronRecord [
  <!ELEMENT patronRecord (Item*)>
  <!ATTLIST patronRecord firstName CDATA #REQUIRED>
  <!ATTLIST patronRecord lastName CDATA #REQUIRED>
  <!ELEMENT Item (title,Authors,callNumber,due,overdue)>
  <!ELEMENT title (#PCDATA)>
  <!ELEMENT Authors (#PCDATA)>
  <!ELEMENT callNumber (#PCDATA)>
  <!ELEMENT due (#PCDATA)>
  <!ELEMENT overdue (#PCDATA)>
]>
<patronRecord firstName="John" lastName="Smith">
   <Item>
      <title>Wireless network security</title>
      <Authors>T.Wrightson</Authors>
      <callNumber>212.12/56</callNumber>
      <due>26-12-2016</due>
      <overdue>NO</overdue>
   </Item>
   <Item>
      <title>T. Tao</title>
      <Authors>Analysis</Authors>
      <callNumber>515/305</callNumber>
      <due>23-12-2016</due>
      <overdue>NO</overdue>
   </Item>
   <Item>
      <title>The art of computer programming</title>
      <Authors>D.E. Knuth</Authors>
      <callNumber>005.1/300</callNumber>
      <due>25-11-2016</due>
      <overdue>YES</overdue>
   </Item>
   <Item>
      <title>Python for dummies</title>
      <Authors>S. Maruch and A. Ranum</Authors>
      <callNumber>145.3/57</callNumber>
      <due>01-10-2016</due>
      <overdue>YES</overdue>
   </Item>
</patronRecord>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:template match="/patronRecord">
      <html>
         <body>
            <xsl:for-each select="Item">
               <xsl:value-of select="title" />
               <br />
               <xsl:value-of select="Authors" />
               <br />
               <xsl:value-of select="callNumber" />
               <br />
               <xsl:value-of select="due" />
               <br />
               <xsl:value-of select="overdue" />
               <br />
            </xsl:for-each>
         </body>
      </html>
   </xsl:template>
</xsl:stylesheet>

]>
无线网络安全
T.莱特森
212.12/56
26-12-2016
不
陶哲轩
分析
515/305
23-12-2016
不
计算机编程的艺术
D.E.克努斯
005.1/300
25-11-2016
对
傻瓜巨蟒
S.Maruch和A.Ranum
145.3/57
01-10-2016
对
XSL

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="Question2.xsl" type="text/xsl" ?>
<!DOCTYPE patronRecord [
  <!ELEMENT patronRecord (Item*)>
  <!ATTLIST patronRecord firstName CDATA #REQUIRED>
  <!ATTLIST patronRecord lastName CDATA #REQUIRED>
  <!ELEMENT Item (title,Authors,callNumber,due,overdue)>
  <!ELEMENT title (#PCDATA)>
  <!ELEMENT Authors (#PCDATA)>
  <!ELEMENT callNumber (#PCDATA)>
  <!ELEMENT due (#PCDATA)>
  <!ELEMENT overdue (#PCDATA)>
]>
<patronRecord firstName="John" lastName="Smith">
   <Item>
      <title>Wireless network security</title>
      <Authors>T.Wrightson</Authors>
      <callNumber>212.12/56</callNumber>
      <due>26-12-2016</due>
      <overdue>NO</overdue>
   </Item>
   <Item>
      <title>T. Tao</title>
      <Authors>Analysis</Authors>
      <callNumber>515/305</callNumber>
      <due>23-12-2016</due>
      <overdue>NO</overdue>
   </Item>
   <Item>
      <title>The art of computer programming</title>
      <Authors>D.E. Knuth</Authors>
      <callNumber>005.1/300</callNumber>
      <due>25-11-2016</due>
      <overdue>YES</overdue>
   </Item>
   <Item>
      <title>Python for dummies</title>
      <Authors>S. Maruch and A. Ranum</Authors>
      <callNumber>145.3/57</callNumber>
      <due>01-10-2016</due>
      <overdue>YES</overdue>
   </Item>
</patronRecord>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:template match="/patronRecord">
      <html>
         <body>
            <xsl:for-each select="Item">
               <xsl:value-of select="title" />
               <br />
               <xsl:value-of select="Authors" />
               <br />
               <xsl:value-of select="callNumber" />
               <br />
               <xsl:value-of select="due" />
               <br />
               <xsl:value-of select="overdue" />
               <br />
            </xsl:for-each>
         </body>
      </html>
   </xsl:template>
</xsl:stylesheet>







您的尝试以何种方式失败?您上一个问题的重复答案以何种方式无效?“跨来源请求被阻止:同一来源策略不允许在file:///Users/benharrington/Documents/UNI/CSIT128/Assignment%206/Question2.xsl. (原因:CORS请求不是http)。”@martinhonnenchrome多年来一直禁止引用基于文件URI的XSLT,Firefox最近也这样做了。因此,您需要通过HTTP加载XML和XSLT,例如从本地web服务器安装。在Chrome的情况下,还有一个命令行选项来显式地允许文件访问。我认为IE仍然允许它,不确定Edge将来打算在哪里转移到Chromium的渲染引擎。建议转换服务器端以避免所有浏览器混淆。