无法通过XSLT将IE显示在IE中作为HTML显示

时间:2013-03-17 15:38:43

标签: xslt xslt-2.0 atom-feed

我创建了一个.xsl文件来转换原子Feed,以便在浏览器中进行友好查看。在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>

1 个答案:

答案 0 :(得分: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元素的“version”属性更改为4.0,而不是1.0。

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

编辑:实际上,这可能是因为IE7.0及更高版本中的默认行为。进入工具 - &gt;互联网选项 - &gt;内容 - &gt;设置(对于Feed和Web切片),您应该看到选项'打开Feed阅读视图。尝试取消勾选,重新启动IE,看看是否有效。