BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


Add/Edit your code items
Search the code library
Browse for the code library


SQL XML
How to select DISTINCT items from XML via XSLT
How to convert Word (RTF) documents to XML for auto publication
Creating SQL Statements with XSLT
SQL straight to XML w/ transform
History Of XML
History Of XML And What Is XML.
Order Automation
You enjoy while you are away and let your machine do the job for you.
SQL Server 2000 User Defined Functions - A Powerful concept
XML/XSLT Maker
Generic ADO recordset to HTML table using XML / XSL
How to display the first three nodes of a XML file with XmlDocument?
What is the usage of the XmlDataDocument?


 
 

<< SEOSystem.XML >>


By Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First Posted 05/13/2002
Times viewed 205

How to call out to a COM component's method through XSLT


Summary This snippet shows you how to call into a COM component's method from within an XSL Stylesheet. Note that the creation of the component is not within the scope of this small article, and is assumed to be part of your basic skills.

You can call out into a COM component's method from within your XSL Stylesheet as shown in the following example (using JavaScript and ASP 3.0 on IIS 5.0/W2K): 1. in your ASP page, create the COM object (note that "SQL2XML.Orders" is just an example of a dll I created in VB6) var myObj = Server.createObject("SQL2XML.Orders"); This COM component accesses the SQL Pubs database and executes a Stored Procedure against it to get some specific Order Details. 2. then, load the XSL Stylesheet and get it compiled var xslProc = getProcessor("myCust.xsl"); function getProcessor(transformName) { var xslDoc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument"); var xslTemplate = new ActiveXObject("MSXML2.XSLTemplate"); xslDoc.async = false; xslDoc.load(Server.mapPath(transformName)); xslTemplate.stylesheet = xslDoc; xslProcessor = xslTemplate.createProcessor(); return xslProcessor; } 3. now, add your COM object to the XSL processor xslProc.addObject(myObj,"urn:schemas-microsoft-com:xml-sql"); 4. then, add parameters when you are ready to perform the XSLT // transform the XML source and display it transformData(srcDoc,xslProc,strConn,strQuery); function transformData(srcDoc,xslProc,strConn,strQuery) { xslProc.input = srcDoc; // here you can add any parameter you like xslProc.addParameter("strConn", strConn, ""); xslProc.addParameter("strQuery", strQuery, ""); xslProc.transform(); Response.Write(xslProc.output); return true; } Note that srcDoc is declared like this and gets loaded the XML source data: var srcDoc = Server.CreateObject("MSXML2.ServerXMLHTTP"); and that strConn and strQuery are strings and define the connection details to the SQL database when the XSLT is performed. See the XSL Stylesheet below. Finally, I must mention also that this example uses version-independent ProgIDs, which you may wish to change to version-dependent ones for version 3.0 or 4.0 of MSXML. If you do so, take care that you do this for ALL instantiated dlls, and in a consistent way, i.e. do not use different versions as this will generate problems.

Additional information

Further additional information


Rate this article on a scale of 1 to 10 (0 votes, average 0)

Your vote :  

<< SEOSystem.XML >>





Leave a comment for this article
Your name
Your email (optional)
Your comment
Optional: Upload an attachment
Enter the code shown:

 
 

    Email TopXML