次の方法で共有


transformNodeToObject Method

 

Processes this node and its children using the supplied XSL Transformations (XSLT) style sheet and returns the resulting transformation in the supplied object.

JScript Syntax

oXMLDOMNode.transformNodeToObject(stylesheet, outputObject);  

Parameters

stylesheet
An object. A valid XML document or DOM node that consists of XSLT elements that direct the transformation of this node.

outputObject
An object. On return, contains the product of the transformation of this XML document based on the XSLT style sheet. If the variant represents the DOMDocument object, the document is built according to its properties and its child nodes are replaced during this transformation process. The XML transformation can also be sent to a stream.

Example

The following Microsoft JScript example sets up the new XML document object named result before making the call to transformNodeToObject.

Note

You can use hello.xml and hello.xsl in the Hello World! (XSLT) topic topic to run this sample code.

// Load data.  
var source = new ActiveXObject("Msxml2.DOMDocument.6.0");  
source.async = false;  
source.load("hello.xml");  
if (source.parseError.errorCode != 0) {  
   var myErr = source.parseError;  
   WScript.Echo("You have error " + myErr.reason);  
} else {  
   // Load style sheet.  
   var stylesheet = new ActiveXObject("Msxml2.DOMDocument.6.0");  
   stylesheet.async = false;  
   stylesheet.load("hello.xsl");  
   if (stylesheet.parseError.errorCode != 0) {  
      var myErr = stylesheet.parseError;  
      WScript.Echo("You have error " + myErr.reason);  
   } else {  
      // Set up the resulting document.  
      var result = new ActiveXObject("Msxml2.DOMDocument.6.0");  
      result.async = false;  
      result.validateOnParse = true;  
      // Parse results into a result DOM Document.  
      WScript.Echo(source.transformNodeToObject(stylesheet, result));  
   }  
}  

C/C++ Syntax

HRESULT transformNodeToObject(  
    IXMLDOMNode *stylesheet,  
    VARIANT outputObject);  

Parameters

stylesheet[in]
A valid XML document or DOM node that consists of XSL elements that direct the transformation of this node.

outputObject[in]
An object that contains the product of the transformation of this XML document based on the XSLT style sheet. If the variant represents DOMDocument, the document is built according to its properties and its child nodes are replaced during this transformation process. If the variant contains an IStream interface, the XML transformation is sent to this stream.

Return Values

S_OK
The value returned if successful.

E_INVALIDARG
The value returned if the stylesheet or outputObject parameter is Null.

Example

This example sets up the new DOMDocument object and puts it into a VARIANT before making the call to transformNodeToObject.

// p is the XML source that is to be transformed, pXSL is the style sheet.  
// Create an empty DOM document for the result. (Error checking omitted   
// for brevity.)  
hr = CoCreateInstance(CLSID_DOMDocument60, NULL, CLSCTX_INPROC_SERVER,  
    IID_IXMLDOMDocument, (void**)&pDoc);   
hr = pDoc->QueryInterface(IID_IDispatch, (void **)&pDisp);  
vObject.vt = VT_DISPATCH;   // the new object   
vObject.pdispVal = pDisp;   
hr = p->transformNodeToObject(pXSL, vObject);   // Transformation is  
                                                // present in pDoc.  

Remarks

The stylesheet parameter must be either a DOMDocument node, in which case the document is assumed to be an XSLT style sheet, or a DOM node in the XSLT style sheet, in which case this node is treated as a standalone style sheet fragment.

The source node defines a context in which the style sheet operates, but navigation outside this scope is allowed. For example, a style sheet can use the id function to access other parts of the document.

This method supports both standalone and embedded style sheets and also provides the ability to run a localized style sheet fragment against a particular source node.

The transformNodeToObject method always generates a Unicode byte-order mark, which means it cannot be used in conjunction with other Active Server Pages (ASP) Response.Write or Response.BinaryWrite calls.

For more information about XSLT, see the XSLT Reference.

This member is an extension of the World Wide Web Consortium (W3C) DOM.

Versioning

Implemented in: MSXML 3.0 and MSXML 6.0

See Also

Using XSLT with the DOM or SAX
IXMLDOMAttribute
IXMLDOMCDATASection
IXMLDOMCharacterData
IXMLDOMComment
IXMLDOMDocument-DOMDocument
IXMLDOMDocumentFragment
IXMLDOMDocumentType
IXMLDOMElement
IXMLDOMEntity
IXMLDOMEntityReference
IXMLDOMNode
IXMLDOMNotation
IXMLDOMProcessingInstruction
IXMLDOMText