addObject Method (IXSLProcessor)
Adds objects into a style sheet.
JScript Syntax
objXSLProcessor.addObject(obj, namespaceURI);
Parameters
obj
The object to pass in. Optionally, you can pass a null value here to signal to the processor that an object previously added should be released.
namespaceURI
The namespace to use inside the style sheet to identify the object.
Example
The following script example passes an object to the style sheet.
var xsldoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.6.0");
var xmldoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.6.0");
var xsltemp = new ActiveXObject("Msxml2.XSLTemplate.6.0");
var xslproc;
xsldoc.load("sampleXSLWithObject.xml");
if (xsldoc.parseError.errorCode != 0) {
var myErr = xsldoc.parseError;
WScript.Echo("You have error " + myErr.reason);
} else {
xsltemp.stylesheet = xsldoc.documentElement;
xslproc = xsltemp.createProcessor();
xmldoc.loadXML("<level>Twelve</level>");
xslproc.input = xmldoc;
xslproc.addObject(xmldoc, "urn:my-object");
xslproc.transform();
WScript.Echo(xslproc.output);
}
Resource File
The JScript example uses the following file.
sampleXSLWithObject.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:template match="/">
<xsl:element name="stage">
<xsl:value-of select="myObj:get-text()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Output
<?xml version="1.0" encoding="UTF-16"?>
<stage>Twelve</stage>
C/C++ Syntax
Parameters
obj[in]
The object to pass in. Optionally, you can pass a NULL IDispatch here to signal to the processor that an object previously added should be released.
namespaceURI[in]
The namespace that will be used inside the style sheet to identify the object.
Return Values
E_FAIL if the value of the readyState
property is READYSTATE_INTERACTIVE
.
Remarks
Numbers are coerced to double, everything is coerced into a string, and objects return an error.
The syntax get-
is used to retrieve the property value exposed by the object that was passed into the style sheet. In the preceding example, the value for the property 'text'
was retrieved as follows:
<xsl:value-of select="myObj:get-text()"/>
For example, if the object that was passed into the style sheet included a property called sheepcount
, you would use the following syntax to retrieve the value of that property.
<xsl:value-of select="myObj:get-sheepcount()"/>
Versioning
Implemented in: MSXML 3.0 and MSXML 6.0