Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to have browsers ignore or override xml-stylesheet processing instructions?

I'm trying to write a bookmarklet to help some QA testers submit useful debugging information when they come across issues. Currently I can set window.location to a URL that provides this debugging information, but this resource is an XML document with an xml-stylesheet processing directive.

It would actually be more convenient if the testers were able to see either the raw XML data as plain text, or the default XML rendering for IE and Firefox.

Does anyone know a way to disable or override xml-stylesheet directives provided inside an XML document, using Internet Explorer or Firefox?

Edit: I've opened a bounty on this question. Requirements:

  • Client-side code only, no user intervention allowed
  • Solutions for both IE and Firefox needed (they can be different solutions)
  • Disabling stylesheet processing and rendering it as text is acceptable
  • Overriding stylesheet processing with a custom XSL is acceptable
  • Rendering the XML with the browser default XML stylesheet is acceptable
like image 992
Steven Huwig Avatar asked Apr 22 '09 15:04

Steven Huwig


2 Answers

EDIT: too bad, though all seemed fine in the preview, the clickable examples seem to mess up things... Maybe the layout is fine in the history.

I've heard, but cannot validate for IE, that both IE and Firefox support the "view-source:" pseudo-protocol. Firefox on Mac indeed understands it, but Safari does not.

The following bookmarklet will not trigger the XSLT transformation specified in the XML. And though Firefox will render this using some colours, it does not execute the default transformation it would normally use for XML without any XSLT (so, the result of view-source does NOT yield a collapsable document tree that Firefox would normally show):

javascript:(function(){
  var u = 'http://www.w3schools.com/xsl/cdcatalog_with_ex1.xml';
  var w = window.open();
  w.document.location.href = 'view-source:' + u;
})()

When fetching the document using Ajax then one is not limited to the alert oneporter used, but can display it in a new window as well. Again: this will not invoke the XSLT transformation that is specified:

javascript:(function(){
  var u = 'http://www.w3schools.com/xsl/cdcatalog_with_ex1.xml';

  var w = window.open(); /* open right away for popup blockers */

  var x = new XMLHttpRequest();
  x.open('GET', u, true); 
  x.onreadystatechange = function(){
    if(x.readyState == 4){
      w.document.open('text/html');
      /* hack to encode HTML entities */
      var d = document.createElement('div'); 
      var t = document.createTextNode(x.responseText); 
      d.appendChild(t);
      w.document.write('<html><body><pre>' 
          + d.innerHTML + '</pre></body></html>');
      w.document.close();
      w.focus();
    }
  };
  x.send(null); 
})()
like image 166
Arjan Avatar answered Sep 28 '22 04:09

Arjan


Can't you just do "View Source" in both browsers?

like image 38
user95902 Avatar answered Sep 28 '22 04:09

user95902