This topic has not yet been rated - Rate this topic

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 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.

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

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()) {}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.