Transform Method (String, String)

XslCompiledTransform.Transform Method (String, String)

Executes the transform using the input document specified by the URI and outputs the results to a file.

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

public void Transform(
	string inputUri,
	string resultsFile


Type: System.String

The URI of the input document.

Type: System.String

The URI of the output file.


The inputUri or resultsFile value is null.


There was an error executing the XSLT transform.


The input document cannot be found.


The inputUri or resultsFile value includes a filename or directory cannot be found.


The inputUri or resultsFile value cannot be resolved.


An error occurred while processing the request


inputUri or resultsFile is not a valid URI.


There was a parsing error loading the input document.

This method uses a default XmlUrlResolver with no user credentials to resolve the input and output documents. If any of these resources are located on a network resource that requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

An XmlReader with default settings is used to load the input document. DTD processing is disabled on the XmlReader. If you require DTD processing, create an XmlReader with this feature enabled, and pass it to the Transform method.

The following example executes a transform and outputs to a file.

// Load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();

// Execute the transform and output the results to a file.
xslt.Transform("books.xml", "books.html");

The sample uses the following two input files:


<?xml version='1.0'?>
<!-- This file represents a fragment of a book store inventory database -->
  <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
    <title>The Autobiography of Benjamin Franklin</title>
  <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
    <title>The Confidence Man</title>
  <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
    <title>The Gorgias</title>


<xsl:stylesheet xmlns:xsl="" version="1.0">
<xsl:template match="bookstore">
      <TABLE BORDER="2">
        <xsl:apply-templates select="book"/>
<xsl:template match="book">
    <TD><xsl:value-of select="@ISBN"/></TD>
    <TD><xsl:value-of select="title"/></TD>
    <TD><xsl:value-of select="price"/></TD>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft