Question

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 the 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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top