xsl_mop-up.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // -*-coding: latin-1;-*-
  2. // Time-stamp: "2006-05-17 22:06:46 ADT" sburke@cpan.org
  3. // A workaround for XSL-to-XHTML systems that don't
  4. // implement XSL 'disable-output-escaping="yes"'.
  5. //
  6. // sburke@cpan.org, Sean M. Burke.
  7. // - I hereby release this JavaScript code into the public domain.
  8. var is_decoding;
  9. var DEBUG = 0;
  10. function complaining (s) { alert(s); return new Error(s,s); }
  11. if(!( document.getElementById && document.getElementsByName ))
  12. throw complaining("Your browser is too old to render this page properly."
  13. + " Consider going to getfirefox.com to upgrade.");
  14. function check_decoding () {
  15. var d = document.getElementById('cometestme');
  16. if(!d) {
  17. throw complaining("Can't find an id='cometestme' element?");
  18. } else if(!('textContent' in d)) {
  19. // It's a browser with a halfassed DOM implementation (like IE6)
  20. // that doesn't implement textContent! Assume that if it's that
  21. // dumb, it probably doesn't implement disable-content-encoding.
  22. } else {
  23. var ampy = d.textContent;
  24. if(DEBUG > 1) { alert("Got " + ampy); }
  25. if(ampy == undefined) throw complaining("'cometestme' element has undefined text content?!");
  26. if(ampy == '' ) throw complaining("'cometestme' element has empty text content?!" );
  27. if (ampy == "\x26" ) { is_decoding = true; }
  28. else if (ampy == "\x26amp;" ) { is_decoding = false; }
  29. else { throw complaining('Insane value: "' + ampy + '"!'); }
  30. }
  31. var msg =
  32. (is_decoding == undefined) ? "I can't tell whether the XSL processor supports disable-content-encoding!D"
  33. : is_decoding ? "The XSL processor DOES support disable-content-encoding"
  34. : "The XSL processor does NOT support disable-content-encoding"
  35. ;
  36. if(DEBUG) alert(msg);
  37. return msg;
  38. }
  39. function go_decoding () {
  40. check_decoding();
  41. if(is_decoding) {
  42. DEBUG && alert("No work needs doing -- already decoded!");
  43. return;
  44. }
  45. var to_decode = document.getElementsByName('decodeme');
  46. if(!( to_decode && to_decode.length )) {
  47. DEBUG && alert("No work needs doing -- no elements to decode!");
  48. return;
  49. }
  50. if(!( ( "innerHTML" in to_decode[0]) && ( "textContent" in to_decode[0]) ))
  51. throw complaining( "Your JavaScript version doesn't implement DOM " +
  52. "properly enough to show this page correctly. " +
  53. "Consider going to getfirefox.com to upgrade.");
  54. var s;
  55. for(var i = to_decode.length - 1; i >= 0; i--) {
  56. s = to_decode[i].textContent;
  57. if(
  58. s == undefined ||
  59. (s.indexOf('&') == -1 && s.indexOf('<') == -1)
  60. ) {
  61. // the null or markupless element needs no reworking
  62. } else {
  63. to_decode[i].innerHTML = s; // that's the magic
  64. }
  65. }
  66. return;
  67. }
  68. //End