Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass param to XSL in IE using javascript (firefox works)

Status
Not open for further replies.

jdbolt

Programmer
Aug 10, 2005
89
CA
I use the following line to pass a parameter to the XSL document

Code:
xsltProcessor.setParameter(null, parameterName, parameterValue);

However, I am not sure about how to do this in IE, heere is my complete code:

Code:
	if (window.ActiveXObject) {
		//Transform the XML document
		document.getElementById(outputTag).innerHTML = xmlDoc.transformNode(xslDoc);
	} else {
		
		// If using mozilla we have to use the XSLTProcessor
		var xsltProcessor = new XSLTProcessor();
		
		xsltProcessor.importStylesheet(xslDoc);

		if (parametersToPass) {

			var i = 0;
		
			while (i < parametersToPass.length) {
				var parameterName = parametersToPass[i];
				i++;
				var parameterValue = parametersToPass[i];
				i++;

				xsltProcessor.setParameter(null, parameterName, parameterValue);
			}
		}

		var fragment = xsltProcessor.transformToFragment(xmlDoc, document);
		
		// Output the XSL
		document.getElementById(outputTag).innerHTML = "";	
		document.getElementById(outputTag).appendChild(fragment);
	}
 
This code will work in IE:
Code:
var xml = new ActiveXObject("MSXML2.DomDocument.3.0");
xml.async = false;
xml.load("yourXmlFile.xml");

var xsl = new ActiveXObject("MSXML2.FreeThreadedDomDocument.3.0");
xsl.async = false;
xsl.load("yourXslFile.xsl");

var template = new ActiveXObject("MSXML2.XSLTemplate")
template.stylesheet = xsl
processor = template.createProcessor()

processor.input = xml
processor.addParameter("param1", "param1value")
processor.addParameter("param2", "someOtherValue")
//and so on

processor.transform()
var result = processor.output;

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top