This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Passing a param to a stylesheet using MSXML3
- To: <xsl-list at mulberrytech dot com>
- Subject: RE: Passing a param to a stylesheet using MSXML3
- From: "Chris Bayes" <Chris at Bayes dot co dot uk>
- Date: Thu, 24 Aug 2000 10:16:27 +0100
- Reply-To: xsl-list at mulberrytech dot com
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@mulberrytech.com
>[mailto:owner-xsl-list@mulberrytech.com]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