function renderMathML(tgt, source) {
  srcout = '<?xml version="1.0"?>'
         + '<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN"'
         + ' "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd">'
         + '<?xml-stylesheet type="text/xsl" href="mathml.xsl"?>'
         + source;  
  var req = new XMLHttpRequest();
  req.open("GET", "mathml.xsl", false);
  req.send(null);
  processor = new XSLTProcessor();
  processor.importStylesheet(req.responseXML);
  var frag = processor.transformToFragment((new DOMParser()).parseFromString(srcout, 'application/xml'),document);
  while (tgt.lastChild) tgt.removeChild(tgt.lastChild);
  tgt.appendChild(frag);
}
function domath() {
  alldivs = document.getElementsByTagName("div");
  for (i=0; i<alldivs.length; i++)
    if (alldivs[i].hasAttribute("class") && alldivs[i].getAttribute("class").toLowerCase()=="math") {
      displaystyle=true;
      renderMathML(alldivs[i],parser.parse(alldivs[i].textContent));
    }
  allspans = document.getElementsByTagName("span");
  for (i=0; i<allspans.length; i++)
    if (allspans[i].hasAttribute("class") && allspans[i].getAttribute("class").toLowerCase()=="math") {
      displaystyle=false;
      renderMathML(allspans[i],parser.parse(allspans[i].textContent));
    }
}
document.getElementsByTagName("body")[0].setAttribute("onload","domath()");


