Microsoft XML SDK 2.6 - XML Reference

addObject Method

Used to pass objects into a style sheet. Numbers are coerced to double, everything is coerced into a string, and objects return an error.

objXSLProcessor.addObject(obj, namespaceURI)

Parameters

obj
Object to pass in.
namespaceURI
The namespace to use inside the style sheet to identify the object.

Example

The following example passes an object to the stylesheet:

Dim xsldoc As New MSXML2.FreeThreadedDOMDocument
Dim xmldoc As New MSXML2.FreeThreadedDOMDocument
Dim xsltemp As New MSXML2.XSLTemplate
Dim xslproc As MSXML2.IXSLProcessor

xsldoc.Load "d:\inetpub\wwwroot\sampleXSLWithObject.xml"
Set xsltemp.stylesheet = xsldoc.documentElement
Set xslproc = xsltemp.createProcessor
xmldoc.loadXML "<foo>foo</foo>"
xslproc.input = xmldoc

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

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="bar">
   <xsl:value-of select="myObj:get-text()"/>
   </xsl:element>
</xsl:template>
</xsl:stylesheet>

Output

<?xml versio="1.0" encoding="UTF-16"?>
<bar>
foo
</bar>

See Also

Applies To: XSLProcessor Object