addObject Method (IXSLProcessor)
Adds objects into a style sheet.
objXSLProcessor.addObject(obj, namespaceURI);
Parameters
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); }
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>
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()"/>