Zzzbla said:
anyone has a live example of loading an xml file from a server, an xslt
file from the server, then transforming the xml using the xslt and
outputing the results (preferably with appendChild)?
I'm trying to write a function to do just that (given url to xml, url
to xslt and elementid). Works a charm on IE. Can't get it to work with
Firefox.
(One more sample besides the one by Martin Honnen)
Full sample at <
http://jsnet.sourceforge.net/tmp/xslt/dxslt.html>
That may be confusing because MSXML and Gecko are using different
patterns.
In MSXML you
1) obtaining XML data
2) obtaining XSL template
3) applying XSL template onto XML data; this automatically invokes
XSLT processor
// 1
var xml = new ActiveXObject('Microsoft.XMLDOM');
xml.async = false;
xml.load('demo.xml');
// 2
var xsl = new ActiveXObject('Microsoft.XMLDOM');
xsl.async = false;
xsl.load('demo.xsl');
// 3
document.body.
insertAdjacentHTML('beforeEnd',
xml.transformNode(xsl));
In Gecko you
1) creating an instance of XSLT processor
2) loading XML data to be processed
3) loading XSL template to be used
4) "charging" the processor with XSL template
5) passing XML data through the processor.
// 1
var XSLT = new XSLTProcessor;
// 2
var $xml = new XMLHttpRequest;
$xml.open('GET', 'demo.xml', false);
$xml.overrideMimeType('text/xml');
$xml.send(null);
var xml = $xml.responseXML;
// 3
var $xsl = new XMLHttpRequest;
$xsl.open('GET', 'demo.xsl', false);
$xsl.overrideMimeType('text/xml');
$xsl.send(null);
var xsl = $xsl.responseXML;
// 4
XSLT.importStylesheet(xsl);
// 5
document.body.
appendChild(XSLT.transformToFragment(xml, document));
Full sample at <
http://jsnet.sourceforge.net/tmp/xslt/dxslt.html>
P.S. I wanted to reference a MDC source first - this raised again my
suspicion that there is some kind of sabotage by anonymous Wiki
editors. Way too many - IMHO - articles are not just not full or
erroneous. Not just that: they are rather sophistically written with a
lot of convincing code samples but with a few key errors or omissions
well hidden here and there.
<
http://developer.mozilla.org/en/docs/Using_the_Mozilla_JavaScript_interface_to_XSL_Transformations>
is very demonstrative in this aspect.
That can a winter paranoia from my side of course.