Transforming to an XmlReader
The XslTransform class has several Transform overloads that return transformation results as an XmlReader object. These overloads can be used to load the transformation results into an in-memory representation (such as XmlDocument or XPathDocument) without incurring the overhead of serialization and deserialization of the resulting XML tree. The following C# code shows how to load the transformation results into an XmlDocument object.
// Load the style sheet
XslTransform xslt = new XslTransform();
xslt.Load("MyStylesheet.xsl");
// Transform input document to XmlDocument for additional processing
XmlDocument doc = new XmlDocument();
doc.Load(xslt.Transform(input, (XsltArgumentList)null));
The XslCompiledTransform class does not support transforming to an XmlReader object. However, you can do something similar by using the CreateNavigator method to load the resulting XML tree directly from an XmlWriter. The following C# code shows how to accomplish the same task using XslCompiledTransform.
// Transform input document to XmlDocument for additional processing
XmlDocument doc = new XmlDocument();
using (XmlWriter writer = doc.CreateNavigator().AppendChild()) {
xslt.Transform(input, (XsltArgumentList)null, writer);
}
Discretionary Behavior
The W3C XSL Transformations (XSLT) Version 1.0 Recommendation includes areas in which the implementation provider may decide how to handle a situation. These areas are considered to be discretionary behavior. There are several areas where the XslCompiledTransform behaves differently than the XslTransform class. For more information, see Recoverable XSLT Errors.
Extension Objects and Script Functions
XslCompiledTransform introduces two new restrictions on the use of script functions:
Only public methods may be called from XPath expressions.
Overloads are distinguishable from each other based on the number of arguments. If more than one overload has the same number of arguments, an exception will be raised.
In XslCompiledTransform, a binding (method name lookup) to script functions occurs at compile time, and style sheets that worked with XslTranform may cause an exception when they are loaded with XslCompiledTransform.
XslCompiledTransform supports having msxsl:using and msxsl:assembly child elements within the msxsl:script element. The msxsl:using and msxsl:assembly elements are used to declare additional namespaces and assemblies for use in the script block. See Script Blocks Using msxsl:script for more information.
XslCompiledTransform prohibits extension objects that have multiple overloads with the same number of arguments.
MSXML Functions
Support for additional MSXML functions have been added to the XslCompiledTransform class. The following list describes new or improved functionality: