nedcomp hosting homepage

Producten en diensten
Dedicated servers
Datacenter informatie
Partners, resellers
Helpdesk informatie
Technische docs, tools
Support homepage
ASP componenten
Praktische ASP, ASP.NET
Visual route server
Whois (domein gegevens)
Software documentatie
Whitepapers
Zoeken
Nedcomp / algemeen

Zoeken
 

Copyright © Nedcomp Hosting
Telefoon nr :   +31 184 670111
Fax nummer :   +31 184 631384
E-mailadres :   info@nedcomp.nl
 

Microsoft XML Core Services (MSXML) 4.0 - DOM Reference

IXSLTemplate

Used for caching compiled XSL Transformations (XSLT) templates.

[C/C++]

Example

The following C++ example demonstrates the use of a single style sheet with multiple XML files. The style sheet is loaded once and cached into the IXSLTemplate object.

#import "msxml4.dll"
using namespace MSXML2;

#define CHECK_AND_RELEASE(pInterface)  \
if(pInterface) \
{\
pInterface->Release();\
pInterface = NULL;\
}\

#define RELEASE(pInterface)  \
{\
pInterface->Release();\
pInterface = NULL;\
}\


BOOL XSLTemplateDemo()
{
   BOOL bResult = FALSE;
   short sResult = FALSE;
   IXMLDOMDocument2 *pStyleSheet=NULL;
   IXMLDOMDocument2 *pIXMLDOMDocument2 =NULL;
   IXSLTemplate *pIXSLTemplate=NULL;
   IXSLProcessor *pIXSLProcessor=NULL;
   IXMLDOMDocument2 *pIXMLDOMDocument=NULL;
   HRESULT hr;
   VARIANT varValue;

   try
   {
      hr = CoCreateInstance(CLSID_XSLTemplate40, NULL, CLSCTX_SERVER, 
         IID_IXSLTemplate, (LPVOID*)(&pIXSLTemplate));
      SUCCEEDED(hr) ? 0 : throw hr;
      
      if(pIXSLTemplate)
      {
         hr=CoCreateInstance(CLSID_FreeThreadedDOMDocument40, NULL,
                  CLSCTX_SERVER, IID_IXMLDOMDocument2,
                  (LPVOID*)(&pStyleSheet));
         SUCCEEDED(hr) ? 0 : throw hr;
         
         if(pStyleSheet)
         {
            hr=pStyleSheet->put_async(VARIANT_FALSE);
            if(SUCCEEDED(hr))
            {
               hr=pStyleSheet->load(_variant_t( 
               _T("d:\\inetpub\\wwwroot\\samplexsl.xml")), &sResult);
               if(SUCCEEDED(hr) && (sResult==VARIANT_TRUE))
               {
                  hr=pIXSLTemplate->putref_stylesheet(pStyleSheet);
                  if(SUCCEEDED(hr))
                  {
                     hr=pIXSLTemplate->createProcessor(&pIXSLProcessor);
                     SUCCEEDED(hr) ? 0 : throw hr;
                     if(pIXSLProcessor)
                     {
                        hr=CoCreateInstance(CLSID_DOMDocument40, NULL,
                              CLSCTX_SERVER, IID_IXMLDOMDocument2,
                                    (LPVOID*)(&pIXMLDOMDocument));
                        SUCCEEDED(hr) ? 0 : throw hr;

                        if(pIXMLDOMDocument)
                        {
                           hr=pIXMLDOMDocument->put_async(VARIANT_FALSE);
                           if(SUCCEEDED(hr))
                           {
                              hr=pIXMLDOMDocument->load(_variant_t(
                           _T("d:\\inetpub\\wwwroot\\samplexmldtd.xml")),
                                 &sResult);
                              if(SUCCEEDED(hr) && (sResult==VARIANT_TRUE))
                              {
                                 hr=pIXSLProcessor->put_input(_variant_t(
                                    pIXMLDOMDocument));
                                 if(SUCCEEDED(hr))
                                 {
                                    hr=pIXSLProcessor->transform(
                                             &sResult);
                                    if(SUCCEEDED(hr)&&(sResult==
                                                VARIANT_TRUE))
                                    {
                                       pIXSLProcessor->get_output(
                                                &varValue);
                                       ::MessageBox(NULL, 
                                          _bstr_t(varValue),
                                          _T("Transformed 
                                             Output"), MB_OK);
                                    }
                                 }
                              }
                           }
                           RELEASE(pIXMLDOMDocument);
                        }
                           // Load another document.
                        hr=CoCreateInstance(CLSID_DOMDocument40, NULL,
                              CLSCTX_SERVER, IID_IXMLDOMDocument2, 
                                 (LPVOID*)(&pIXMLDOMDocument2));
                        SUCCEEDED(hr) ? 0 : throw hr;

                        if(pIXMLDOMDocument2)
                        {
                           hr=pIXMLDOMDocument2->put_async(VARIANT_FALSE);
                           if(SUCCEEDED(hr))
                           {
                              // Load some XML into the document.
                              hr=pIXMLDOMDocument2->loadXML(
                                 _T("<COLLECTION\ xmlns:dt=\"urn:schemas-
                                 microsoft-\ com:datatypes\">\
                                 <DATE dt:dt=\"datetime\">1998-10-
                                       13T15:56:00\ 
                                          </DATE><BOOK><TITLE>Cosmos</TITLE> \
                                 <AUTHOR>Carl Sagan</AUTHOR> \
                                 <PUBLISHER>Ballantine Books</PUBLISHER> \
                                 </BOOK> \
                                 </COLLECTION>"), &sResult);
                              if(SUCCEEDED(hr) && (sResult==VARIANT_TRUE))
                              {
                                 // Use the same processor.
                                 hr=pIXSLProcessor->put_input(_variant_t(
                                    pIXMLDOMDocument2));
                                 if(SUCCEEDED(hr))
                                 {
                                    hr=pIXSLProcessor->transform(
                                             &sResult);
                                    if(SUCCEEDED(hr)&&(sResult==
                                                VARIANT_TRUE))
                                    {
                                       pIXSLProcessor->get_output(
                                                &varValue);
                                       ::MessageBox(NULL, 
                                          _bstr_t(varValue),
                                          _T("Transformed 
                                    Output"), MB_OK);
                                    }
                                 }
                              }
                           }
                           RELEASE(pIXMLDOMDocument2);
                        }
                        RELEASE(pIXSLProcessor);
                     }
                  }
               }
            }
            RELEASE(pStyleSheet);
         }
         RELEASE(pIXSLTemplate);
      }
   }
   catch(...)
   {
      CHECK_AND_RELEASE(pIXSLProcessor);
      CHECK_AND_RELEASE(pIXSLTemplate);
      CHECK_AND_RELEASE(pStyleSheet);
      CHECK_AND_RELEASE(pIXMLDOMDocument);
      CHECK_AND_RELEASE(pIXMLDOMDocument2);
      DisplayErrorToUser();
   }
   return bResult;
}

Remarks

Before Microsoft® XML Core Services (MSXML) 2.6, every call to the transformNode or transformNodeToObject method had to recompile the style sheet because the style sheet was simply passed as an IXMLDOMNode. You can increase performance by caching the compiled style sheet and reusing it with the IXSLTemplate object.

To cache a compiled XSLT style sheet, load an XSLT style sheet into an IXSLTemplate object. This object is free-threaded and stateless, so it can be stored in shared Active Server Pages (ASP) application state. Then to transform a given document using this template, create an IXSLProcessor object using the createProcessor method. The IXSLProcessor object stores the state for one transform call and has a rental-threading model.

This object is an extension of the World Wide Web Consortium (W3C) Document Object Model (DOM).

Requirements

Implementation: msxml4.dll, msxml2.lib

[C/C++]

Header and IDL files: msxml2.h, msxml2.idl

Version-Dependent ProgID: Msxml2.XSLTemplate.4.0

Version-Dependent CLSID: 88D969C3-F192-11D4-A65F-0040963251E5

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

IXSLTemplate Members


Download de SDK