0

I have an xml file as this

  <math><apply><power></power><ci>x</ci><cn>2</cn></apply></math>

I have xsl file as xsl file

I am trying to take this xsl file as basis and trying to convert it into math expression using javascript and xml by refering the logic in xsl

<html>
<head>
<script>
function loadXMLDoc(filename)
{
if (window.ActiveXObject)
  {
  xhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
else 
  {
  xhttp = new XMLHttpRequest();
  }
xhttp.open("GET", filename, false);
try {xhttp.responseType = "msxml-document"} catch(err) {} // Helping IE11
xhttp.send("");
return xhttp.responseXML;
}

function displayResult()
{
xml = loadXMLDoc("cdcatalog.xml");
xsl = loadXMLDoc("cdcatalog.xsl");
// code for IE
if (window.ActiveXObject || xhttp.responseType == "msxml-document")
  {
  ex = xml.transformNode(xsl);
  document.getElementById("example").innerHTML = ex;
  }
// code for Chrome, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
  {
  xsltProcessor = new XSLTProcessor();
  xsltProcessor.importStylesheet(xsl);
  resultDocument = xsltProcessor.transformToFragment(xml, document);
  document.getElementById("example").appendChild(resultDocument);
  }
}
</script>
</head>
<body onload="displayResult()">
<div id="example" />
</body>
</html>

But i am not getting it as enter image description here instead i am getting it as x2.instead of x^2.How to make alteration to the xsl to get that as x^2 .

When I checked I found the power part in xsl is as follows:

<!-- 4.4.3.7 power -->
<xsl:template mode="c2p" match="mml:apply[*[1][self::mml:power]]">
<mml:msup>
<xsl:apply-templates mode="c2p" select="*[2]">
  <xsl:with-param name="p" select="5"/>
</xsl:apply-templates>
<xsl:apply-templates mode="c2p" select="*[3]">
  <xsl:with-param name="p" select="5"/>
</xsl:apply-templates>
</mml:msup>
</xsl:template>

What change should I do in xsl to get x^2 instead of x2??

user1989
  • 163
  • 7
  • 1
    PLEASE DON'T POST THE SAME QUESTION TWICE! http://stackoverflow.com/questions/32179237/content-mathml-to-infix-notation-using-ctop-xsl-not-getting-as-desired-format – michael.hor257k Aug 25 '15 at 06:34
  • @michael.hor257k but noone suggesting any solutions. Stuck for 3 days. Hope you can help. I will delete one!! – user1989 Aug 25 '15 at 06:38
  • the stylesheet shows a lot of namespace prefix `mml:` and your XML has none. – Joel M. Lamsen Aug 25 '15 at 07:45

0 Answers0