首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XSL不工作

XSL不工作
EN

Stack Overflow用户
提问于 2012-08-28 21:39:39
回答 2查看 7K关注 0票数 1

我有一个奇怪的problem.XSL不工作的xml.This是我的xml和xsl代码:

代码语言:javascript
复制
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xsl-stylesheet type= "text/xsl" href= "w3c.xsl"?>
<catalog>
    <cd>
        <title>Greatest Hits</title>
        <artist>Dolly Parton</artist>
        <country>USA</country>
        <company>RCA</company>
        <price>9.90</price>
        <year>1982</year>
    </cd>
    <cd>
        <title>Eros</title>
        <artist>Eros Ramazzotti</artist>
        <country>EU</country>
        <company>BMG</company>
        <price>9.90</price>
        <year>1997</year>
    </cd>
    <cd>
        <title>Romanza</title>
        <artist>Andrea Bocelli</artist>
        <country>EU</country>
        <company>Polydor</company>
        <price>10.80</price>
        <year>1996</year>
    </cd>
</catalog>

这是我的xsl:

代码语言:javascript
复制
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <body>
  <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

注意:

我从W3C上获取了这段代码,因此它是一个可以工作的代码。我在谷歌上搜索了很多,但找不到任何有效的解决方案。我使用了ie、firefox和chrome在它们中的任何一个上都不能工作。我在我的远程服务器上测试过它不工作either.The错误是“这个XML文件似乎没有任何与之相关的样式信息。文档树如下所示。“occurs.In href同样的错误我已经尝试了从完整路径到文件名的所有可能的链接。我也尝试了chrome的--.The- file -access-occurs.In-files,但work.Please不能帮助我解决这个问题。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-08-28 21:42:15

请注意,XML文件的第二行写着:

代码语言:javascript
复制
<?xsl-stylesheet type= "text/xsl" href= "w3c.xls"?>

注意到w3c.xls (而不是xsl ?)你的文件名是什么?注意,is是xml-stylesheet,而不是xsl-stylesheet

所以这应该可以做到:

代码语言:javascript
复制
<?xml-stylesheet type= "text/xsl" href= "w3c.xsl"?>
票数 3
EN

Stack Overflow用户

发布于 2012-08-28 21:55:01

我不能重现这个问题。

当提供的XSLT样式表:

代码语言:javascript
复制
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <body>
  <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

对提供的XML文档应用了(我拥有的所有9种不同的XSLT处理器)。

代码语言:javascript
复制
<catalog>
    <cd>
        <title>Greatest Hits</title>
        <artist>Dolly Parton</artist>
        <country>USA</country>
        <company>RCA</company>
        <price>9.90</price>
        <year>1982</year>
    </cd>
    <cd>
        <title>Eros</title>
        <artist>Eros Ramazzotti</artist>
        <country>EU</country>
        <company>BMG</company>
        <price>9.90</price>
        <year>1997</year>
    </cd>
    <cd>
        <title>Romanza</title>
        <artist>Andrea Bocelli</artist>
        <country>EU</country>
        <company>Polydor</company>
        <price>10.80</price>
        <year>1996</year>
    </cd>
</catalog>

生成了正确的结果

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <body>
        <h2>My CD Collection</h2>
        <table border="1">
            <tr bgcolor="#9acd32">
                <th>Title</th>
                <th>Artist</th>
            </tr>
            <tr>
                <td>Greatest Hits</td>
                <td>Dolly Parton</td>
            </tr>
            <tr>
                <td>Eros</td>
                <td>Eros Ramazzotti</td>
            </tr>
            <tr>
                <td>Romanza</td>
                <td>Andrea Bocelli</td>
            </tr>
        </table>
    </body>
</html>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12160515

复制
相关文章

相似问题

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