开发者

Is it possible to apply an XSLT transform to a DOM element?

I have a webpage that has many user-generated elements that need to be "cleaned" and I'd like the cleanup to be expressed as an XSLT transform because it suits t开发者_StackOverflow中文版he purpose quite well.

Is there a way to apply an XSLT transform to part of a webpage? (And does the source element have to be checked by something akin to tagsoup first, to make sure it's well-formed?)

All the examples I find are about fetching an XML file and an XSL file, via Ajax, and running one against the other, but not taking a subset of the DOM and running an XSLT on it. Can it be done?


What is the context you want to do that in? Is the document ("web page") already loaded in a browser window? Some browsers expose an API to Javascript to apply XSLT to DOM nodes e.g. Mozilla introduced an API and other browsers like Opera have copied it: https://developer.mozilla.org/en/using_the_mozilla_javascript_interface_to_xsl_transformations.

And of course there is Saxon-CE that runs inside the browser: http://www.saxonica.com/ce/doc/contents.html. That even allows you to apply XSLT 2.0 to DOM nodes.


Since HTML is not XML, I don't think you will be able to perform an XSLT transform on an HTML page. However, you will be able to do it on an XHTML page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜