XML+XSLT+javascript

wxdqz

New Member
I've a question regarding xml transformation from javascript.
I have the following script working properly on FF 2.0 browser with "test.xml"
getting rendered properly using "test.xsl" style-sheet. However. the "test.xml"
contains the following line:

<?xml-stylesheet type="text/xsl" href=http://www.webdeveloper.com/forum/archive/index.php/"test.xsl"?>

I feel that if i have that line in the xml file, then i should not have to
explicitly transform the "test.xml" as i have done below. However, i cant seem
to be able to find a way to do so. My googling efforts have been in vain so
far. I do think that should be possible, because typing in the URL for test.xml
causes the browser to automatically fetch the test.xsl and render it properly. I
feel that should be possible from javascript as well.

I'm still a beginner with XML/XSLT, so please excuse my ignorance and i
appreciate and pointers experts here can provide.

<script>
function foo()
{
var processor = new XSLTProcessor();
httpRequest = new XMLHttpRequest();
httpRequest.open('GET', 'test2.xsl', false);
httpRequest.send(null);
var xsl = httpRequest.responseXML;
alert('RNP');
processor.importStylesheet(xsl);
httpRequest = new XMLHttpRequest();
httpRequest.open('GET', 'test.xml', false);
httpRequest.send(null);
x=processor.transformToDocument(httpRequest.responseXML);
document.documentElement.innerHTML=x.documentElement.innerHTML;
}
</script>
<body onload="foo();">
Before Test
</body>
 
Back
Top