Adds objects into a style sheet.
objXSLProcessor.addObject(obj, namespaceURI);
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>
objXSLProcessor.addObject(obj, namespaceURI)
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>
HRESULT addObject (IDispatch* obj, BSTR namespaceURI);
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 in the upper-left corner of the page.
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()"/>
Applies to: IXSLProcessor