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

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

问题描述

我有一系列的哪个参考XSLT文件来呈现为HTML浏览器中的XML文件。其中的一些有联系这会,一个常规页面上,执行一个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服务,在点击一个链接,并接收,然后通过AJAX加工成HTML以同样的方式与原始页面,然后插入到一个DIV XML当前页面。

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下载到由它解析的关联使用Javascript XSLT的XML

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)。 (这两个 xmlDoc中名为xsldoc 是XML文档对象,可通过例如XHR加载)。在Opera,火狐等,你应该建立一个 XSLTProcessor中第一(姑且称之为 PROC ),然后调用 proc.importStylesheet(名为xsldoc),最后你可以在 XSLTProcessor中 transformToXXX 方法使用code>。 (例如: proc.transformToFragment(xmlDoc中,文件)来创建一个DOMDocumentFragment可以使用插入的文件对象适当的的appendChild()电话。)

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天全站免登陆