Hi,
I’m trying to transform XML with XSLT in Mozilla and it doesn’t seam to work.
All the XML Data is stored in a Data Island inside the HTML site I call the JavaScript from.
Here’s what I’ve already done
So I can use the loadXML() Funktion in Mozilla I extended the Document class as told in [URL]http://www.webreference.com/programming/javascript/domwrapper/index.html
[code]
Document.prototype.loadXML = function(strXML) {
//create a DOMParser
var objDOMParser = new DOMParser();
//create new document from string
var objDoc = objDOMParser.parseFromString(strXML, “text/xml”);
//make sure to remove all nodes from the document
while (this.hasChildNodes())
this.removeChild(this.lastChild);
//add the nodes from the new document
for (var i=0; i < objDoc.childNodes.length; i++) {
//import the node
var objImportedNode = this.importNode(objDoc.childNodes[i], true);
//append the child to the current document
this.appendChild(objImportedNode);
} //End: for
} //End: function
And also extended the functionality to transfer it back to XML and added the xml attribute
[code]
/**
* add the xml attribute to the node class
* Everytime the .xml attribute is called it will be transformed to string
*/
Node.prototype.__defineGetter__(“xml”, function () {
var oSerializer = new XMLSerializer();
return oSerializer.serializeToString(this, “text/xml”);
});
Now I’m creating 2 Dom Documents and load the xml Data for the XML and the XSLT.
[code]
objSrcTree = document.implementation.createDocument(“”, “”, null);
objXSLT = document.implementation.createDocument(“”, “”, null);
objSrcTree.async = false;
try {
objSrcTree.loadXML(document.getElementById(“xmlData”).innerHTML);
objXSLT.loadXML(document.getElementById(“xsltData”).innerHTML);
}
catch(Exception){
alert(“loadXML failed in Mozilla”);
}
This works gread. An alert(objSrcTree.xml) or alert(objXSLT.xml) show’s the 2 Documents ?
Now I create the XSLT Prozessor and try to transform
[code]
objXSLTProc = new XSLTProcessor();
objXSLTProc.importStylesheet(objXSLT);
try {
var resultDOM = objXSLTProc.transformToDocument(objSrcTree);
var sResult = resultDOM.xml;
alert(sResult);
}
catch(Exeption){
alert(“XSLT Transformation failed”);
}
He’s in the try block because I don’t get the alert(“XSLT Transformation failed”). On debugging it runs over it and alert(sResult) shows an empty document. Document because alert(resultDOM) gives “XML Document Object”
What am I missing???
Greetings
Spanky 😡
PLEASE HELP ME 😮