Subject: RE: [xsl] transformation question From: Pieter Reint Siegers Kort <pieter.siegers@xxxxxxxxxxx> Date: Wed, 14 Apr 2004 11:24:41 -0500 |
Hi Vel., > If you can, please send me a sample ASP with the declaration you mentioned. > It would help me to change many of my xslt stylesheets. Of course, here it is, but it is written using J(ava)Script (note that I've left out the date function calls like getHora() and getFecha()): <%@ Language="JScript" %> <!--#include file="Script/LibJscript.js"--> <% // create the ServerXMLHTTP object for getting the XML data // using SQL Query Templates (SQLXML 3.0) var srcDoc = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0"); var strMethod = "GET"; var strAsync = "False"; var strUserId = "sa"; var strPassword = "password"; var IdCd = ""; var Hora = ""; var Fecha = ""; var Fecha1 = ""; var Fecha2 = ""; var Fecha3 = ""; var Fecha4 = ""; IdCd = new String(Request.QueryString("IdCd")); Hora = getHora(); Fecha = getFecha(); Fecha1 = getFecha1(); Fecha2 = getFecha2(); Fecha3 = getFecha3(); Fecha4 = getFecha4(); var strURL = "http://localhost/dbClimaX/templates/climax.xml?IdCd=" + IdCd.toString(); // get the XML running the SQL query template srcDoc = GetXML(strMethod,strURL,strAsync,strUserId,strPassword); // then, load the XSL Stylesheet and get it compiled // by using the Application Object created in Global.asa var xslProc = getProcessorApp("ClimaX_elnortePortada"); // finally, transform the XML source and display it transformDataS(srcDoc,xslProc,IdCd,Fecha,Hora,Fecha1,Fecha2,Fecha3,Fecha4); %> LibJscript.js ============= <% // Get XML from SQL 2K using a template query function GetXML(strMethod,strURL,strAsync,strUserId,strPassword) { try { // initialize an http request and pass the URL and credentials srcDoc.open(strMethod,strURL,strAsync,strUserId,strPassword); // send the http request (get the page) srcDoc.send(); // return the result as an object return srcDoc.responseXML; } catch (e) { Response.Write("Error: " + e.description); } } // creates a processor instance at page level using the XSLTemplate object // by using the Application variable created in Global.asa function getProcessorApp(XslStylesheetName) { xslProcessor = Application(XslStylesheetName).createProcessor(); return xslProcessor; } // transforms the XML using the compiled XSL Stylesheet // in this case, the response object is used to output the result tree function transformDataS(srcDoc,xslProc,IdCd,Fecha,Hora,Fecha1,Fecha2,Fecha3,Fecha4) { // point to the compiled processor xslProc.input = srcDoc; // add the parameters used inside the stylesheet xslProc.addParameter("Hora", Hora, ""); xslProc.addParameter("Fecha", Fecha, ""); xslProc.addParameter("Fecha1", Fecha1, ""); xslProc.addParameter("Fecha2", Fecha2, ""); xslProc.addParameter("Fecha3", Fecha3, ""); xslProc.addParameter("Fecha4", Fecha4, ""); xslProc.addParameter("IdCd", IdCd.toString(), ""); // perform the XSL Transformation xslProc.transform(); // write result to browser Response.Write(xslProc.output); return true; } %> Finally, Global.asa is also mentioned - below is the important part (it creates a global compiled stylesheet thereby eliminating the need for parsing and compiling the stylesheet; creating the processor happens at page level since it is not possible to do that at Application level due to the threading model). You may need to transfer this part to page level if your stylesheet changes frequently. <SCRIPT LANGUAGE="JavaScript" RUNAT="Server"> ... function Application_OnStart() { /* Creates a processor using the XSLTemplate object, i.e., loads the XSL Stylesheet, compiles it, and returns it in a processor object; checks if the XSL Processor was already created; if not, it gets created in an application variable which is then accessible to any user of the application and thus scalable */ if ("" + Application("ClimaX_elnortePortada") == "undefined") { var xslDoc = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.4.0"); Application("ClimaX_elnortePortada") = Server.CreateObject("MSXML2.XSLTemplate.4.0"); xslDoc.async = false; xslDoc.load(Server.mapPath("/climax/xsl/ClimaXNorte12.xsl")); // compile the stylesheet Application("ClimaX_elnortePortada").stylesheet = xslDoc; } } ... </SCRIPT> Cheers, Pieter <prs/> http://www.pietsieg.com http://www.pietsieg.com/dotnetnuke Contributor on www.ASPToday.com Co-author on "Professional ASP.NET XML with C#", July 2002 by Wrox Press
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] transformation question, velmurugan mariappan | Thread | Re: Fw: [xsl] xmlns added to some <, Ian Lang |
Re: [xsl] Importing multiple XML fi, G. Ken Holman | Date | RE: [xsl] Problem with rendering of, Richard . McMillian |
Month |