XmlDocument Input to XslTransform

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

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

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 transform As XslTransform = new XslTransform()
transform.Load("book.xsl")
Dim rdr As XmlReader = trans.Transform(doc, Nothing, Nothing)
while (rdr.Read())
end while
[C#]
XmlDocument doc = new XmlDocument();
doc.Load("books.xml");
XslTransform transform = new XslTransform();
transform.Load("book.xsl");
XmlReader rdr = trans.Transform(doc, null, null);
while (rdr.Read()) {}

Due of the editing capability of the XmlDocument, using the XmlDocument class as input to a transform is less performant than using an XPathDocument for the XSLT transformations, as the XPathDocument is optimized for XPath queries due to the internal storage.

See Also

XmlDocument Members | XmlDocument Class | XSLT Transformations with the XslTransform Class | XslTransform Class Implements the XSLT Processor | XPathNavigator in Transformations | XPathNodeIterator in Transformations | XPathDocument Input to XslTransform | XmlDataDocument Input to XslTransform