T
Tom Cole
I am trying to create a cross-browser implementation that will take an
XML file, apply a XSL stylesheet to it and return a DOM stack of the
styled XML.
In non-IE browsers I am using something like the following
successfully:
NOTE: value is a global variable and element & url are passed to the
method. Element is the document element that is to contain the parsed
XML DOM and url points to the XSL stylesheet.
if (typeof XSLTProcessor != 'undefined') {
var processor = new XSLTProcessor();
var request = getXMLHttpRequest();
if (request) {
request.open("GET", url, false);
request.send(null);
var xsl = request.responseXML;
processor.importStylesheet(xsl);
var fragment = processor.transformToFragment(value, document);
if (element)
element.appendChild(fragment);
}
else {
return;
}
}
In IE there is no XSLTProcessor, but there is the XMLDOM ActiveX
component. Problem is I don't know how to get it to return me an XML
DOM, just text:
else {
var processor = new ActiveXObject("Microsoft.XMLDOM");
if (processor) {
processor.async = false;
processor.load(url);
var xmlString = value.transformNode(processor);
if (element) {
element.innerHTML = xmlString;
}
else {
return;
}
}
I've only found the transformNode method which returns a String, but
nothing that will return actual DOM objects.
Thanks in advance.
XML file, apply a XSL stylesheet to it and return a DOM stack of the
styled XML.
In non-IE browsers I am using something like the following
successfully:
NOTE: value is a global variable and element & url are passed to the
method. Element is the document element that is to contain the parsed
XML DOM and url points to the XSL stylesheet.
if (typeof XSLTProcessor != 'undefined') {
var processor = new XSLTProcessor();
var request = getXMLHttpRequest();
if (request) {
request.open("GET", url, false);
request.send(null);
var xsl = request.responseXML;
processor.importStylesheet(xsl);
var fragment = processor.transformToFragment(value, document);
if (element)
element.appendChild(fragment);
}
else {
return;
}
}
In IE there is no XSLTProcessor, but there is the XMLDOM ActiveX
component. Problem is I don't know how to get it to return me an XML
DOM, just text:
else {
var processor = new ActiveXObject("Microsoft.XMLDOM");
if (processor) {
processor.async = false;
processor.load(url);
var xmlString = value.transformNode(processor);
if (element) {
element.innerHTML = xmlString;
}
else {
return;
}
}
I've only found the transformNode method which returns a String, but
nothing that will return actual DOM objects.
Thanks in advance.