0

我创建了一个.xsl文件来转换原子提要,以便在浏览器中友好地查看。在 Chrome 中查看时效果很好,但 IE (9.0.811) 样式表被忽略。

我的问题是:我可以改变什么,以便 Internet Explorer 处理样式表,就像它处理 Chrome 一样?

示例原子文件:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/css/atom.xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title><![CDATA[A title here]]></title>
    <subtitle><![CDATA[A CDATA description here.]]></subtitle>
    <link href="http://www.site.com/channel" title="a title" rel="alternate" type="text/html" hreflang="en" />
    <link href="http://www.site.com/channel/atom" rel="self" type="application/rss+xml" />
    <id>http://www.site.com/channel</id>
    <rights>All content &#xA9; 2006-2013 Site Name unless otherwise noted. All rights reserved.</rights>
    <updated>2011-12-18T20:34:31Z</updated>
    <category term="Domain: Cat/Subcat" label="Heirarchy Label" />
    <author>
            <name>Editor's Desk</name>
            <email>editors@site.com</email>
            <uri>http://www.site.com/members/username</uri>
    </author>
    <logo>http://www.site.com/img/logo.gif</logo>
    <entry>
        <title><![CDATA[Some CDATA here]]></title>
        <link href="http://www.site.com/channel/article-name" title="Article Name" rel="alternate" type="text/html" hreflang="en" />
        <id>http://www.site.com/channel/article-name</id>
        <content type="html"><![CDATA[<h3>New Post - Title</h3><p>A new post has been published titled "<a href="http://www.site.com/channel/article-name" title="Article Title">Article Title</a>".</p><p>Click the link above to go to the full biography and to view other user's ratings and comments.</p><p>Article posted in: <i>section -> subsection -> subcat</i>.</p>]]></content>
        <author>
            <name>Editor's Desk</name>
            <email>editors@site.com</email>
            <uri>http://www.site.com/members/username</uri>
        </author>
        <category term="Domain: Cat/Subcat" label="text label here" />
        <rights>All content &#xA9; 2006-2013 Site Name unless otherwise noted. All rights reserved.</rights>
        <published>2011-12-18T20:34:31Z</published>
        <updated>2011-12-18T20:34:31Z</updated>
    </entry>

以及该文件的相关摘录.xsl

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom">
    <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" />
    <xsl:template match="/">
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
                <title>
                    <xsl:value-of select="atom:feed/atom:title"/>
                </title>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <link rel="stylesheet" href="/css/style.css" />
            </head>
            <body>
                <div id="container">

                    <xsl:variable name="feed-title">
                        <xsl:value-of select="atom:feed/atom:title" />
                    </xsl:variable>
                    <xsl:variable name="feed-uri">
                        <xsl:value-of select="atom:feed/atom:link[2]/@href" />
                    </xsl:variable>
                    <xsl:variable name="web-uri">
                        <xsl:value-of select="atom:feed/atom:link[1]/@href" />
                    </xsl:variable>


                    <h1>Atom Feed - <xsl:value-of select="atom:feed/atom:title" /></h1>
                    <p><xsl:value-of select="atom:feed/atom:subtitle" /></p>
                    <p><a href="{$feed-uri}"><img src="/img/i/atom-feed.png" alt="{$feed-title}" /></a> - <a href="{$feed-uri}"><xsl:value-of select="atom:feed/atom:title" /></a><br /><xsl:value-of select="feed/link[1]/@href" /></p>

                    <p>To subscribe to this RSS feed:</p>
                    <ul>
                        <li>Drag the orange RSS button or text link above into your news reader</li>
                        <li>Cut and paste this page's URL into your news reader</li>
                    </ul>
                    <p>Alternatively, you can <a title="{$feed-title}" href="{$web-uri}">view the actual online version</a> of this content.</p>

                </div>
                <div id="footer">
                    <xsl:value-of select="atom:feed/atom:rights" />
                </div>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>
4

1 回答 1

2

这可能是因为您的样式表是 XSLT2.0,但 Microsoft 不支持,因此 IE 也不支持。我在您的 XSLT 示例中看不到任何需要 XSLT2.0 的内容,因此也许您可以尝试将样式表的版本设置为 1.0 而不是 2.0。

<xsl:stylesheet version="1.0" 
     xmlns:html="http://www.w3.org/TR/REC-html40" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     xmlns:atom="http://www.w3.org/2005/Atom">

此外,您可能想尝试将 xsl:output 元素的“版本”属性更改为 4.0,而不是 1.0。

<xsl:output method="html" version="4.0" encoding="UTF-8" indent="yes" />

编辑:实际上,这可能是因为 IE7.0 及更高版本中的默认行为。进入工具 -> Internet 选项 -> 内容 -> 设置(用于提要和网页快讯),您应该会看到“打开提要阅读视图”选项。尝试取消勾选,然后重新启动 IE,看看是否有效。

于 2013-03-17T16:36:57.130 回答