This documentation is archived and is not being maintained.

XslTransform.Transform Method (IXPathNavigable, XsltArgumentList, Stream, XmlResolver)

Transforms the XML data in the IXPathNavigable using the specified args and outputs the result to a Stream.

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

public void Transform(
	IXPathNavigable input,
	XsltArgumentList args,
	Stream output,
	XmlResolver resolver


Type: System.Xml.XPath.IXPathNavigable

An object implementing the IXPathNavigable interface. In the .NET Framework, this can be either an XmlNode (typically an XmlDocument), or an XPathDocument containing the data to be transformed.

Type: System.Xml.Xsl.XsltArgumentList

An XsltArgumentList containing the namespace-qualified arguments used as input to the transformation.

Type: System.IO.Stream

The stream to which you want to output.

Type: System.Xml.XmlResolver

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

The XmlResolver is not cached after the Transform method completes.


There was an error processing the XSLT transformation.

Note: This is a change in behavior from earlier versions. An XsltException is thrown if you are using Microsoft .NET Framework version 1.1 or earlier.


The XslTransform class is obsolete in the .NET Framework version 2.0. The XslCompiledTransform class is the new XSLT processor. For more information, see Using the XslCompiledTransform Class and Migrating From the XslTransform Class.

XslTransform supports the XSLT 1.0 syntax. The XSLT style sheet must include the namespace declaration xmlns:xsl=

The args are matched with the xsl:param elements defined in the style sheet.

Transformations apply to the document as a whole. In other words, if you pass in a node other than the document root node, this does not prevent the transformation process from accessing all nodes in the loaded document. To transform a node fragment, you must create an XmlDocument containing just the node fragment and pass that XmlDocument to the Transform method.

The following example performs a transformation on a node fragment.

 XslTransform xslt = new XslTransform();     
 XmlDocument doc = new XmlDocument();
 // Create a new document containing just the node fragment.
 XmlNode testNode = doc.DocumentElement.FirstChild; 
 XmlDocument tmpDoc = new XmlDocument(); 
 // Pass the document containing the node fragment 
 // to the Transform method.
 Console.WriteLine("Passing " + tmpDoc.OuterXml + " to print_root.xsl");
 xslt.Transform(tmpDoc, null, Console.Out, null);

The example uses the library.xml and print_root.xsl files as input and outputs the following to the console.

 Passing <book genre="novel" ISBN="1-861001-57-5"><title>Pride And Prejudice</title></book> to print_root.xsl 
 Root node is book.


   <book genre='novel' ISBN='1-861001-57-5'>
      <title>Pride And Prejudice</title>
   <book genre='novel' ISBN='1-81920-21-2'>


 <style sheet version="1.0" xmlns="" >
   <output method="text" /> 
   <template match="/">
      Root node is  <value-of select="local-name(//*[position() = 1])" /> 
 </style sheet>

The following example performs a transformation within an ASP.NET page.

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ import NameSpace="System.Web" %>
<%@ Import Namespace="System.Xml.XPath" %>
<%@ Import Namespace="System.Xml.Xsl" %>
   <script language="C#" runat="server">
      void Page_Load(Object sender, EventArgs e) 
         // Load the XML document to transform.
         XPathDocument doc = new XPathDocument(Server.MapPath("books.xml"));

         // Load the stylesheet and perform the transform.
         XslTransform xslt = new XslTransform();
         xslt.Transform(doc, null, Response.OutputStream, null);


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1