1

I'm getting a JSON object back from the API and converting that into XML which is all working okay, however when I try to use that converted object and wrapped it in XSL its not rendering any values in the HTML.

Can I do it something like this?

var x2js = new X2JS();
var json2XMLResult = x2js.json2xml_str(data.Results);

this.da = '<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="../../../config/Customer.xsl" type="text/xsl" ?> <Results>' + json2XMLResult + '</Results>';

and rendering it using document.getElementById().innerHTML

(<HTMLInputElement>document.getElementById('xmlJson')).innerHTML = this.da;

my XSL file:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html"
              doctype-system="about:legacy-compat"
              encoding="UTF-8"
              indent="yes" />

  <xsl:template match="/">
    Account No. is - <xsl:value-of select="./Results/AccountNumber"/>
    Last Name is - <xsl:value-of select="./Results/LastName"/>
  </xsl:template>

</xsl:stylesheet>

Can someone point me to the right direction, please. I've never worked on XML nor XSL before so I'm completely lost.

Checking the HTML source it's commenting out the <?xml> tags. enter image description here

nCore
  • 2,027
  • 7
  • 29
  • 57
  • 1
    The `xml-stylesheet` directive will only really apply if you were navigating to an XML directly in the browser. It will not be evaluated when you use the `innerHTML` property. If you want to apply XSLT on the client, see http://stackoverflow.com/questions/5722410/how-can-i-use-javascript-to-transform-xml-xslt as an example. Having said that, if you are getting back JSON from the client, and are using angularjs, there really should be no need to use XSLT at all. – Tim C Sep 20 '16 at 14:29
  • @TimC reason is I want to render a template using XML rather than doing {{data.object}} in the HTML. – nCore Sep 20 '16 at 14:40
  • Added an image where it shows its commenting out the `` tag. – nCore Sep 20 '16 at 15:13

0 Answers0