addObject Method

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

addObject Method

Adds objects into a style sheet.

[Script]

Script 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.5.0");
var xmldoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.5.0");
var xsltemp = new ActiveXObject("Msxml2.XSLTemplate.5.0");
var xslproc;

xsldoc.load("d:\\inetpub\\wwwroot\\sampleXSLWithObject.xml");
if (xmlDoc.parseError.errorCode <> 0) {
   var myErr = xmlDoc.parseError;
   alert("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();
   alert(xslproc.output);
}

File Name: d:\inetpub\wwwroot\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>
[Visual Basic]

Visual Basic Syntax

objXSLProcessor.addObject(obj, namespaceURI)

Parameters

obj
The object to pass in. Optionally, you can pass a null object value here such as Nothing 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 Visual Basic example passes an object to the style sheet.

Dim xsldoc As New Msxml2.FreeThreadedDOMDocument50
Dim xmldoc As New Msxml2.FreeThreadedDOMDocument50
Dim xsltemp As New Msxml2.XSLTemplate50
Dim xslproc As Msxml2.IXSLProcessor

xsldoc.Load "d:\inetpub\wwwroot\sampleXSLWithObject.xml"
If (xmlDoc.parseError.errorCode <> 0) Then
   Dim myErr
   Set myErr = xmlDoc.parseError
   MsgBox("You have error " & myErr.reason)
Else
   Set xsltemp.stylesheet = xsldoc.documentElement
   Set xslproc = xsltemp.createProcessor
   xmldoc.loadXML "<level>Twelve</level>"
   xslproc.input = xmldoc

   xslproc.addObject xmldoc, "urn:my-object"
   xslproc.Transform
   MsgBox xslproc.output
End If

File Name: d:\inetpub\wwwroot\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++]

C/C++ Syntax

HRESULT addObject (IDispatch* obj, BSTR namespaceURI);

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.

C/C++ Return Values

E_FAIL if the value of the readyState property is READYSTATE_INTERACTIVE.

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.

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()"/>

See Also

Applies to: IXSLProcessor