How would I write a bookmarklet that applies a given XSLT stylesheet to XML file that is displayed in, e.g., firefox? The XML Document is already loaded in the browser and displayed without a stylesheet, and the XSLT is available under a fixed URL which should be encoded in the bookmarklet.
Here is an example:
A bookmarklet for applying an XSLT stylesheet to an XML document - just insert the base64 encoded xsl in atob("") - tested on firefox
javascript: (function() {
var parser = new DOMParser();
var ss = parser.parseFromString(atob(""), 'application/xml');
var xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(ss);
var newdoc = xsltProcessor.transformToDocument(content.document);
var myWindow = window.open("data:text/html," + encodeURIComponent(newdoc.documentElement.innerHTML), "_blank", "");
myWindow.focus();
}());