共用方式為


XmlDocument Input to XslTransform

The XmlDocument class provides editing capabilities for an XML document. If the XML needs to be edited or modified before being sent to the Transform method, load the XML into an XmlDocument, edit it, and send it in to the XslTransform.

Note

The XslTransform class is obsolete in the .NET Framework 2.0. You can perform Extensible Stylesheet Language for Transformations (XSLT) transformations using the XslCompiledTransform class. See Using the XslCompiledTransform Class and Migrating From the XslTransform Class for more information.

The XmlDocument implements the IXPathNavigable interface, so the document can be passed to the Transform method after editing.

Due to the editing capability of the XmlDocument, using the XmlDocument class as input to a transformation is slower than using an XPathDocument for the Extensible Stylesheet Language for Transformations (XSLT) transformations, as the XPathDocument is optimized for XML Path Language (XPath) queries due to the internal storage.

Example

The following code example shows how an XmlDocument can be supplied to the XslTransform, with the output sent to an XmlReader.

Dim doc as XmlDocument = new XmlDocument()  
doc.Load("books.xml")  
Dim trans As XslTransform = new XslTransform()  
trans.Load("book.xsl")  
Dim rdr As XmlReader = trans.Transform(doc, Nothing, Nothing)  
while (rdr.Read())  
end while  
XmlDocument doc = new XmlDocument();  
doc.Load("books.xml");  
XslTransform trans = new XslTransform();  
trans.Load("book.xsl");  
XmlReader rdr = trans.Transform(doc, null, null);  
while (rdr.Read()) {}  

See also