I have created a .xsl file to transform an atom feed for friendly viewing in a browser. It works great when viewed in Chrome, but IE (9.0.811) the style sheet is ignored.

My question is: What can I change so that the stylesheet is processed by Internet Explorer just like it does with Chrome?

The sample atom file:

<?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>

And the relevant excerpt from the .xsl file:

<?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>
有帮助吗?

解决方案

This may be because your stylesheet is XSLT2.0, but this is not supported by Microsoft, and so not supported by IE. I can't see anything in your XSLT sample that requires XSLT2.0, so perhaps you can try setting the version of your stylesheet to 1.0 instead of 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">

Also, you might want to try changing the "version" attribute of your xsl:output element to 4.0, instead of 1.0.

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

EDIT: Actually, this may be because of default behaviour in IE7.0 and above. Go into Tools -> Internet Options -> Content -> Settings (for Feeds and Web Slices), and you should see the option 'Turn on feed reading view. Try un-ticking this, and re-starting IE, to see if that works.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top