Have a nice day everybody
i\'m trying to call a XSLT file from an XML that i\'m rendering using data:text/xml, obtained from a REST. The most basic attempt is to use thi
As this is client-side Javascript inside of web browsers like Firefox or Chrome I would suggest to use XSLTProcessor
to perform the XSLT transformation, you can pull in the XSLT stylesheet using XMLHttpRequest
, parse your responseData
using DOMParser
and then you can use XSLTProcessor
for the transformation.
I don't think you will get the browser to execute an XSLT referenced in the data
URL, unless the XSLT is embedded itself as data:
var encodedXslt = 'data:application/xml,' + encodeURIComponent(document.getElementById('xslt').textContent);
var xmlCode = document.getElementById('xml').textContent;
var pi = '';
var encodedXml = 'data:application/xml,' + encodeURIComponent(pi + xmlCode);
window.frames.xmlDisplay.location.href = encodedXml;
However, it seems only Mozilla swallows that attempt and applies the XSLT, Chrome continues to complain about an unsafe attempt. So I think it is better and more portable to implement any XSLT transformation where you have the input as a Javascript string with XSLTProcessor.