[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Passing a param to a stylesheet using MSXML3

Subject: RE: Passing a param to a stylesheet using MSXML3
From: "Chris Bayes" <Chris@xxxxxxxxxxx>
Date: Thu, 24 Aug 2000 10:16:27 +0100
transformnode param
>From the MSXML 3 documentation

See Also
XSLTemplate JScript Examples

IXSLProcessor Interface
 Microsoft XML SDK 3.0 - XML Reference
IXSLProcessor::addParameter Method
Allows you to pass variables into a style sheet that will be referenced by
<xsl:param> within the style sheet.

Visual Basic Syntax
objXSLProcessor.addParameter(baseName, parameter, namespaceURI)
C/C++ Syntax
HRESULT addParameter (BSTR baseName, VARIANT parameter, BSTR
namespaceURI);
Parameters
baseName [in]
The name that will be used inside the style sheet to identify the parameter
context.
parameter [in]
A number, boolean, string, node list, or node. Passing in a single node will
produce a nodelist that contains one node (shortcut).
namespaceURI [in, optional]
Optional namespace.
C/C++ Return Values
E_FAIL if readyState is READYSTATE_INTERACTIVE.

Remarks
The addParameter method can be called in on TransformNode handlers and
between transform calls (in async processing), and further processing will
use the updated parameter.

C/C++ Example
BOOL XSLProcessorAddParameterDemo ()
{
   BOOL bResult = FALSE;
   short sResult = FALSE;
   HRESULT hr;
   IXMLDOMDocument2 *pStyleSheet=NULL;
   IXSLTemplate *pIXSLTemplate=NULL;
   IXSLProcessor *pIXSLProcessor=NULL;
   VARIANT varValue;

   try
   {
      hr = CoCreateInstance(CLSID_XSLTemplate, NULL, CLSCTX_SERVER,
         IID_IXSLTemplate, (LPVOID*)(&pIXSLTemplate));
      SUCCEEDED(hr) ? 0 : throw hr;

      if(pIXSLTemplate)
      {
         hr=CoCreateInstance(CLSID_FreeThreadedDOMDocument, 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_DOMDocument, NULL,
                           CLSCTX_SERVER, IID_IXMLDOMDocument2,
                           (LPVOID*)(&pIXMLDOMDocument));
                        SUCCEEDED(hr) ? 0 : throw hr;

                        if(pIXMLDOMDocument)
                        {
                           hr=pIXMLDOMDocument->put_async(VARIANT_FALSE);
                           if(SUCCEEDED(hr))
                           {

pIXMLDOMDocument->load(_variant_t( 
                     _T("d:\\inetpub\\wwwroot\\sampleXSLWithParam.xml")),                                  &sResult);
                              if(SUCCEEDED(hr) && (sResult==VARIANT_TRUE))
                              {
                                 hr=pIXSLProcessor->put_input(_variant_t
                                     (pIXMLDOMDocument));
                                 if(SUCCEEDED(hr))
                                 {
                                    hr=pIXSLProcessor->addParameter( 
                                       _T("fooText"), _variant_t(_T("Add                                        Parameter Test")), _T(""));
                                    if(SUCCEEDED(hr))
                                       bResult=TRUE;
                                       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);
                        }
                     }
                  }
               }
            }
            RELEASE(pStyleSheet);
         }
         RELEASE(pIXSLTemplate);
      }
   }
   catch(...)
   {
      CHECK_AND_RELEASE(pIXSLTemplate);
      CHECK_AND_RELEASE(pStyleSheet);
      CHECK_AND_RELEASE(pIXMLDOMDocument);
      DisplayErrorToUser();
   }
   return bResult;
}
The stylesheet ? "d:\\inetpub\\wwwroot\\sampleXSLWithParam.xml"

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns:myObj="urn:my-object">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="fooText"/>

<xsl:template match="/">
<xsl:element name="bar">
<xsl:value-of select="$fooText"/>
</xsl:element>
</xsl:template>

</xsl:stylesheet>
Output (in a message box)

<?xml version=?1.0? encoding=?UTF-16??>
<bar>
Add Parameter Test
</bar>
See Also
XSLTemplate JScript Examples

IXSLProcessor Interface

XML/XSL Portal
http://www.bayes.co.uk/xml


>-----Original Message-----
>From: owner-xsl-list@xxxxxxxxxxxxxxxx
>[mailto:owner-xsl-list@xxxxxxxxxxxxxxxx]On Behalf Of ciaran byrne
>Sent: 24 August 2000 05:33
>To: XSL-List
>Subject: Passing a param to a stylesheet using MSXML3
>
>
>Hi all,
> does anyone know who to pass a parameter to a stylesheet
>in MSXML. Any documentation I've come across seems to only
>refer to VBScript or JScript. I'm more interested in
>doing it using MSXML in VB/C++.
>
>Anyone got any ideas or links ? - much appreciated.
>
>
>
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.