哪个浏览器可以显示由 XSLT 转换的 XML 数据?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3466854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:15:02  来源:igfitidea点击:

Which browser can show XML data transformed by XSLT?

xmlxslt

提问by nonopolarity

say, if there is a file that's call data.xml, and a file that is format.xsl(or is it format.xml?), which is to transform the XML data and format it as well using CSS, then which browser can display it? Which file should be opened? (the .xslor the .xml?)

比方说,如果有一个文件是 call data.xml,还有一个文件是format.xsl(或者是format.xml?),用于转换 XML 数据并使用 CSS 对其进行格式化,那么哪个浏览器可以显示它?应该打开哪个文件?(.xsl.xml?)

Actually I saw in another example that the XSLT file's first line is to href="format.xsl", so I thought the XSLT file is already the .xsl? then how come it is linking to another .xslfile? How many files are there, 2 or 3?

实际上我在另一个例子中看到 XSLT 文件的第一行是 to href="format.xsl",所以我认为 XSLT 文件已经是.xsl? 那么它是如何链接到另一个.xsl文件的呢?有多少个文件,2个还是3个?

回答by Andreas

There are two files, one .xml containing data and one .xsl with the XSLT script for transformation. As of August, 2010, all leading browsers support client side XSLT transformation. Open the .xml file and the associated .xsl file will be used. Usually the script builds an html document which is displayed on the fly. The transformation can also be done by the server with PHP etc.
To associate a XSLT script, the .xml file needs a line like this:

有两个文件,一个包含数据的 .xml 和一个带有用于转换的 XSLT 脚本的 .xsl。截至 2010 年 8 月,所有主流浏览器都支持客户端 XSLT 转换。打开 .xml 文件,将使用关联的 .xsl 文件。通常,脚本会构建一个动态显示的 html 文档。转换也可以由服务器使用 PHP 等完成。
要关联 XSLT 脚本,.xml 文件需要这样一行:

<?xml-stylesheet type="text/xsl" href="script.xsl" ?>

回答by Tim Jansen

Many browsers support the XML-stylesheet processing instruction. If it is included in an XML file and you open this XML with your browser, the browser will load the specified XSLT, run it with the XML file as input and display the XSLT's output instead of the original XML document. The spec can be found here: http://www.w3.org/TR/xml-stylesheet/

许多浏览器支持 XML 样式表处理指令。如果它包含在 XML 文件中并且您使用浏览器打开此 XML,则浏览器将加载指定的 XSLT,以 XML 文件作为输入运行它并显示 XSLT 的输出而不是原始 XML 文档。该规范可以在这里找到:http: //www.w3.org/TR/xml-stylesheet/

Wikipedia's XSLT entryhas an example of how to use the processing instruction. Basically you just need to add this line at the top of your XML file (after the <?xml?> prolog), with 'example2.xsl' being a path to your XSLT file:

维基百科的 XSLT 条目有一个如何使用处理指令的例子。基本上你只需要在你的 XML 文件的顶部添加这一行(在 <?xml?> prolog 之后),'example2.xsl' 是你的 XSLT 文件的路径:

<?xml-stylesheet href="example2.xsl" type="text/xsl" ?>

<?xml-stylesheet href="example2.xsl" type="text/xsl" ?>

Firefox and IE should both support this (and probably many other browsers, but I never tried - this feature is not used that often).

Firefox 和 IE 都应该支持这个(可能还有很多其他浏览器,但我从来没有尝试过——这个功能不经常使用)。

回答by arun

On mac, I tried opening the XML file with Chrome and Safari and neither displayed anything.

在 Mac 上,我尝试使用 Chrome 和 Safari 打开 XML 文件,但均未显示任何内容。

The solution that worked for me is to run xsltprocfrom command line to first get an HTML and then open the HTML with a browser. Here is the command:

对我有用的解决方案是从命令行运行xsltproc以首先获取 HTML,然后使用浏览器打开 HTML。这是命令:

xsltproc <XSL file> <XML file> > test.html

Now open test.htmlwith browser.

现在test.html用浏览器打开。

回答by Rob

Firefox and Internet Explorer (definitely version 6 and up, likely earlier versions too) can parse XML/XSL well. You could actually write a client-side parser in Javascript, both those browsers work well with that.

Firefox 和 Internet Explorer(肯定是版本 6 及更高版本,也可能是早期版本)可以很好地解析 XML/XSL。您实际上可以用 Javascript 编写客户端解析器,这两种浏览器都可以很好地使用它。

You'll probably want to make sure that you don't use any vendor-specific pieces, tho, which can break compatibility (such as <msxsl:script>). The same might apply to other parsers (for example the node-set() function, which isn't the same between MSXML all parsers).

您可能希望确保不使用任何特定于供应商的部分,这可能会破坏兼容性(例如 <msxsl:script>)。这同样可能适用于其他解析器(例如 node-set() 函数,MSXML 所有解析器之间都不相同)。

Within your XSL file, you may include another XSL file. Or more XSL files. That way, you can re-use templates from one XSL file in another.

在您的 XSL 文件中,您可以包含另一个 XSL 文件。或更多 XSL 文件。这样,您可以在另一个 XSL 文件中重复使用模板。

回答by jakefreeberg

I believe support is partial in all browsers.

我相信所有浏览器都提供部分支持。

Here are some charts: http://greenbytes.de/tech/tc/xslt/

以下是一些图表:http: //greenbytes.de/tech/tc/xslt/