Firefox 3 不应用我的 xslt 样式表,但其他浏览器可以
我正在尝试从 Web 服务器提供动态生成的 xml 页面,并从同一 Web 服务器提供自定义的静态 xslt,这会将处理卸载到客户端 Web 浏览器中。
直到最近,我在 Firefox 2、3、IE5、6 和 Chrome 中都运行良好。 不过,最近发生了一些变化,Firefox 3 现在只显示源代码中的文本元素。
页面源代码如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Firefox 2.0 and Internet Explorer 7 use simplistic feed sniffing to override desired presentation behavior for this feed, and thus we are obliged to insert this comment, a bit of a waste of bandwidth, unfortunately. This should ensure that the following stylesheet processing instruction is honored by these new browser versions. For some more background you might want to visit the following bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=338621 -->
<?xml-stylesheet type="text/xsl" href="/WebObjects/SantaPreview.woa/Contents/WebServerResources/Root.xsl"?>
<wrapper xmlns="http://www.bbc.co.uk/ContentInterface/Content" xmlns:cont="http://www.bbc.co.uk/ContentInterface/Content" sceneId="T2a_INDEX" serviceName="DSat_T2">
....
Firebug 显示 Root.xsl 文件正在加载,并且它的响应标头包括行
Content-Type text/xml
我也尝试过使用 application/xml 作为内容类型,但它没有区别:-(
Web Developer Extension 也显示了正确的生成源,如果您保存它并在 Firefox 中加载页面,它会正确显示。
显示问题的 Firefox 版本是 3.0.3
有什么想法吗?可能做错了?
I'm trying to serve dynamically generated xml pages from a web server, and provide a custom, static, xslt from the same web server, that will offload the processing into the client web browser.
Until recently, I had this working fine in Firefox 2, 3, IE5, 6 and Chrome. Recently, though, something has changed, and Firefox 3 now displays just the text elements in the source.
The page source starts like this:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Firefox 2.0 and Internet Explorer 7 use simplistic feed sniffing to override desired presentation behavior for this feed, and thus we are obliged to insert this comment, a bit of a waste of bandwidth, unfortunately. This should ensure that the following stylesheet processing instruction is honored by these new browser versions. For some more background you might want to visit the following bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=338621 -->
<?xml-stylesheet type="text/xsl" href="/WebObjects/SantaPreview.woa/Contents/WebServerResources/Root.xsl"?>
<wrapper xmlns="http://www.bbc.co.uk/ContentInterface/Content" xmlns:cont="http://www.bbc.co.uk/ContentInterface/Content" sceneId="T2a_INDEX" serviceName="DSat_T2">
....
Firebug shows that the Root.xsl file is being loaded, and the response headers for it include the line
Content-Type text/xml
I've also tried it with application/xml as the content type, but it makes no difference :-(
The Web Developer Extension shows the correct generated source too, and if you save this and load the page in Firefox, it displays correctly.
The version of Firefox displaying the problem is 3.0.3
Any ideas what I might be doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
仅显示文本元素是空 XSL 样式表中的行为。
对我来说,这表明您的 xpath 表达式存在问题,并且 xsl:template/@match 属性与源文档不匹配。
您没有提供足够的信息来进一步诊断,所以我只能提供这种盲目的猜测。
编辑:事实证明,问题在于 IE 和 Chrome 默默地接受节点集作为 的参数string-length,而 FF3 没有。 请注意,该规范强制要求使用可选的字符串参数,并且没有指定节点集参数的行为。
Displaying just the text elements is the behavior you would get out of an empty XSL stylesheet.
To me, that suggests that something fishy is going on with your xpath expressions, and that the xsl:template/@match attributes do not match the source document.
You do not provide enough information to diagnose further, so this blind guess is all I can offer.
EDIT: It turned out the problem was that IE and Chrome silently accept a nodeset as argument to string-length, while FF3 does not. Note that the specification mandates an optional string argument and does not specify behavior with a nodeset argument.
如果您使用 NoScript,也会禁用 XSL 样式表,直到您
允许
。If you're using NoScript, that also disables XSL stylesheets until you
Allow <site>
.根据后续调查回答我自己的问题。 ddaa 引导我走向正确的方向。
Firefox 似乎对 xslt 转换非常挑剔。 仔细检查您的 xslt 以确保它没有 IE 和 Chrome 屏蔽的错误。
XML Spy 是一个很好的产品,虽然不便宜,但它会突出显示 xslt 中的一系列错误。 它似乎至少能解决与 Firefox 渲染器一样多的问题。
不幸的是,您似乎不能依赖 Web Developer 扩展来解决问题。
Answering my own question in the light of subsequent investigation. ddaa lead me in the right direction.
Firefox seems to be pretty fussy with xslt conversions. Double-check your xslt to ensure it has no errors that IE and Chrome are masking.
XML Spy is a good, though not cheap, product that will highlight a range of errors in the xslt. It seems to pick up at least as many issues as the Firefox renderer does.
It seems you can't rely on the Web Developer extension to pick up the problem, unfortunately.
我写在这里只是为了后人 - 我也有同样的症状,Firefox 3 也是如此。但是在我的情况下,问题是另一个:
Firefox 似乎真的,真的不喜欢当一个XSL 文件名称中包含下划线
_
。 我的 XSLT 文件的名称类似于my_super_nice_xslt_which_loads_in_opera_and_ie.xsl
。所以,朋友们,我们不要使用下划线。 使用连字符(减号)代替:
my-super-nice-xslt-which-loads-in-opera-and-ie.xsl
。然后它也会在 Firefox 中加载。 我想从现在开始我只会使用带有字母和数字的简单名字。 大家都知道“一朝被蛇咬,十年怕井绳”这句话。 (就我而言,我被咬了两次,但忘记了第一次,所以这次我害羞了四倍。)
I just write here for posterity - I had the same symptom, also Firefox 3. However in my case, the problem was another:
Firefox seems to really, really dislike when an XSL file has an underscore
_
in the name. My XSLT file was called something likemy_super_nice_xslt_which_loads_in_opera_and_ie.xsl
.So, people, let's not use underscores. Use a hyphen (minus) instead:
my-super-nice-xslt-which-loads-in-opera-and-ie.xsl
.Then it will load in Firefox as well. I think I will just use dead simple names with letters and numbers in them from now on. You know the saying, "once bitten, twice shy". (In my case, I was bitten twice, but forgot the first time, so that makes me like four times shy this time.)
尝试将其作为 application/xml 而不是 text/xml 提供
try serving it as application/xml instead of text/xml