使用 Javascript/JQuery 进行 XML/XSL 转换

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14988645/
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-10-26 23:04:54  来源:igfitidea点击:

XML/XSL transform using Javascript/JQuery

javascriptjqueryxmlxslt

提问by cgdeveloper

Can anyone tell me if there is a way to do an XML/XSLT transformation on the client side using Javascript or JQuery, a way that works in all major browsers? (Chrome, Safari, Firefox and IE)? Thanks.

谁能告诉我是否有办法在客户端使用 Javascript 或 JQuery 进行 XML/XSLT 转换,这种方式适用于所有主要浏览器?(Chrome、Safari、Firefox 和 IE)?谢谢。

回答by Tom Davies

I should state from the start that I wrote this script, but if you're looking to just do some transformations and pass some parameters to your XSLT (nothing too fancy) then you can try Magic XML.

我应该从一开始就声明我编写了这个脚本,但是如果您只想进行一些转换并将一些参数传递给您的 XSLT(没什么特别的),那么您可以尝试Magic XML

You can also have it automatically pull in your data and apply transformations by setting some data-attributes on your DOM elements. For example...

您还可以通过data-在 DOM 元素上设置一些属性,让它自动提取数据并应用转换。例如...

<div data-xml="example.xml" data-xslt="transform.xslt"></div>

...would automatically pull in data from example.xml and apply the transform.xslt to it.

...会自动从example.xml 中提取数据并将transform.xslt 应用到它。

It works in Opera, Chrome, Firefox and IE and is open source.

它适用于 Opera、Chrome、Firefox 和 IE,并且是开源的。

回答by Ian Roberts

Have you considered Saxon CE? It used to require a commercial licence for deployment but the latest version has been released as open source.

你考虑过撒克逊 CE吗?它曾经需要商业许可证才能部署,但最新版本已作为开源发布。

回答by John

回答by C. M. Sperberg-McQueen

I've had reasonably good experiences with Sarissa. The transformation interface supported by some XForms engines is also a convenient way to manage transformations in the client.

我与Sarissa 的经历相当不错。一些 XForms 引擎支持的转换接口也是一种在客户端管理转换的便捷方式。