Performance Comparison of XslTransform Inputs


To transform XML into HTML for use on a Web site or to transform it into a document that contains only the fields required you could use the XSLTransform class (found in the System.Xml.Xsl namespace). The XSL transformation uses as input document an XML document through three classes which implements XPathNavigator and IXPathNavigable interface: XmlDocument, XmlDataDocument and XPathDocument. 

XmlDocument class (found in the System.Xml namespace):

This class can be used in cases where a DOM structure must be edited first before XSL transformation. The class extends the XMLNode class. 

XMLDataDocument class (found in the System.Xml namespace):

This class extends the XMLDocument class and can be used when working with Datasets. Provides access either to relational data (through the overloaded method Load) or to XML data (LoadXML method) 

XPathDocument class (found in the System.Xml.XPath namespace):

This class does not extend the XMLNode class (as XMLDocument) but provides a read-only representation of a DOM structure and it is highly optimized for XSLT processing and the XPath data model using the XPath optimization functions on the XPathNavigator

So, I used the following scenario to test if the XPathDocument is the fastest way to input an XML document to the XSL transformation.

I applied the XSL transformation to the each class loaded with the same XML file and outputted the result to the web in an .aspx page.

oTrs.Transform(oDoc, Nothing, sw)
TextBox1.Text = sw.ToString()

Each .aspx page was stressed with against Application Center Test in three different cases (1, 3 and 10 concurrent browser connections). The stress test was performed on 2 different machines and the test duration was 5 minutes.

// XMLDocument Test
// XMLDataDocument Test
// XPathDocument Test

The results (request vs. time) were identical in all cases.



(1)   XPathDocument
(2)   XMLDataDocument
(3)   XMLDocument 


XPathDocument provides the fastest option for transforming XML via XSLT because is optimized for XPath queries due to the internal storage.