从 javascript 调用 XSLT [英] Calling XSLT from javascript

查看:26
本文介绍了从 javascript 调用 XSLT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列 XML 文件,它们引用 XSLT 文件以在浏览器中呈现为 HTML.其中一些链接会在常规页面上执行 AJAX 调用以请求 HTML 并将其插入到页面上已有的 DIV 中.

I have a series of XML files which reference XSLT files to render as HTML in the browser. Some of these have links which would, on a regular page, perform an AJAX call to request HTML and insert it into a DIV already on the page.

我想要做的是从此页面调用 Web 服务,单击链接,然后接收 XML,然后以与原始页面相同的方式将其处理为 HTML,然后通过 AJAX 插入到 DIV 中当前页面.

What I want to do is call a webservice from this page, upon a link click, and receive XML which then is processed into HTML in just the same way as the original page was, and then inserted via AJAX into a DIV on the current page.

我的问题是:我如何让 Javascript 下载的 XML 由它使用 Javascript 的关联 XSLT 解析?

My question is: How would I get the XML which is downloaded by Javascript to be parsed by it's associated XSLT using Javascript?

推荐答案

在 MSIE 中你可以调用 xmlDoc.transformNode(xslDoc).(xmlDocxslDoc 都是 XML 文档对象,可以通过例如 XHR 加载).在 Opera、Firefox 等中,您应该先构造一个 XSLTProcessor(我们称之为 proc),然后调用 proc.importStylesheet(xslDoc),然后最后,您可以使用 XSLTProcessortransformToXXX 方法之一.(例如:proc.transformToFragment(xmlDoc, document) 来创建一个 DOMDocumentFragment,它可以使用适当的 appendChild() 插入到 document 对象中打电话.)

In MSIE you can call xmlDoc.transformNode(xslDoc). (Both xmlDoc and xslDoc are XML document objects, as may be loaded through e.g. XHR). In Opera, Firefox etc. you should construct an XSLTProcessor first (let's call it proc), then call proc.importStylesheet(xslDoc), and finally you can use on of the transformToXXX methods of XSLTProcessor. (E.g.: proc.transformToFragment(xmlDoc, document) to create a DOMDocumentFragment which may be inserted in the document object using an appropriate appendChild() call.)

这篇关于从 javascript 调用 XSLT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆