Transform Method (XmlReader, XsltArgumentList, XmlWriter, XmlResolver)

XslCompiledTransform.Transform Method (XmlReader, XsltArgumentList, XmlWriter, XmlResolver)


Executes the transform using the input document specified by the XmlReader object and outputs the results to an XmlWriter. The XsltArgumentList provides additional run-time arguments and the XmlResolver resolves the XSLT document() function.

Namespace:   System.Xml.Xsl
Assembly:  System.Xml (in System.Xml.dll)

public void Transform(
	XmlReader input,
	XsltArgumentList arguments,
	XmlWriter results,
	XmlResolver documentResolver


Type: System.Xml.XmlReader

An XmlReader containing the input document.

Type: System.Xml.Xsl.XsltArgumentList

An XsltArgumentList containing the namespace-qualified arguments used as input to the transform. This value can be null.

Type: System.Xml.XmlWriter

The XmlWriter to which you want to output.

If the style sheet contains an xsl:output element, you should create the XmlWriter using the XmlWriterSettings object returned from the OutputSettings property. This ensures that the XmlWriter has the correct output settings.

Type: System.Xml.XmlResolver

The XmlResolver used to resolve the XSLT document() function. If this is null, the document() function is not resolved.

Exception Condition

The input or results value is null.


There was an error executing the XSLT transform.

The following example uses an XmlSecureResolver to resolve the XSLT document() function.

// Create a resolver and specify the necessary credentials.
XmlSecureResolver resolver = new XmlSecureResolver(new XmlUrlResolver(), "http://serverName/data/");
System.Net.NetworkCredential myCred;
myCred  = new System.Net.NetworkCredential(UserName,SecurelyStoredPassword,Domain);  
resolver.Credentials = myCred;

XsltSettings settings = new XsltSettings();
settings.EnableDocumentFunction = true;

// Load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("http://serverName/data/xsl/sort.xsl", settings, resolver);

// Transform the file.
using (XmlReader reader = XmlReader.Create("books.xml"))
   using (XmlWriter writer = XmlWriter.Create("output.xml")) 
      xslt.Transform(reader, null, writer, resolver);

.NET Framework
Available since 2.0
Return to top
© 2015 Microsoft