var objXSLProcessor = objXSLTemplate.createProcessor();
var xslt = new ActiveXObject("Msxml2.XSLTemplate.4.0"); var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0"); var xslProc; xslDoc.async = false; xslDoc.load("sample.xsl"); xslt.stylesheet = xslDoc; var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0"); xmlDoc.async = false; xmlDoc.load("books.xml"); xslProc = xslt.createProcessor(); xslProc.input = xmlDoc; xslProc.addParameter("param1", "Hello"); xslProc.transform(); alert(xslProc.output);
File Name: Sample.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:param name="param1"/> <xsl:template match="/"> The parameter value was: <xsl:value-of select="$param1"/> </xsl:template> </xsl:stylesheet>
function loaderXml(xmlSrc,xslsrc,params){ var xmlDoc=new ActiveXObject("Msxml2.DOMDocument.4.0"); xmlDoc.async=false; xmlDoc.load(xmlSrc); var xslDoc=new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0"); xslDoc.async = false; xslDoc.load(xslsrc); var xslt = new ActiveXObject("Msxml2.XSLTemplate.4.0"); xslt.stylesheet = xslDoc; var xslProc = xslt.createProcessor(); xslProc.input = xmlDoc; if(params){ $.each(params,function(name,val){ xslProc.addParameter(name, val); }); } xslProc.transform(); return xslProc.output; }