XslCompiledTransform.Transform XslCompiledTransform.Transform XslCompiledTransform.Transform XslCompiledTransform.Transform Method

Definition

Executes the XSLT transformation.

Overloads

Transform(XmlReader, XsltArgumentList, TextWriter) Transform(XmlReader, XsltArgumentList, TextWriter) Transform(XmlReader, XsltArgumentList, TextWriter) Transform(XmlReader, XsltArgumentList, TextWriter)

Executes the transform using the input document specified by the XmlReader object and outputs the results to a TextWriter. The XsltArgumentList provides additional run-time arguments.

Transform(IXPathNavigable, XsltArgumentList, XmlWriter) Transform(IXPathNavigable, XsltArgumentList, XmlWriter) Transform(IXPathNavigable, XsltArgumentList, XmlWriter) Transform(IXPathNavigable, XsltArgumentList, XmlWriter)

Executes the transform using the input document specified by the IXPathNavigable object and outputs the results to an XmlWriter. The XsltArgumentList provides additional run-time arguments.

Transform(IXPathNavigable, XsltArgumentList, TextWriter) Transform(IXPathNavigable, XsltArgumentList, TextWriter) Transform(IXPathNavigable, XsltArgumentList, TextWriter) Transform(IXPathNavigable, XsltArgumentList, TextWriter)

Executes the transform using the input document specified by the IXPathNavigable object and outputs the results to an TextWriter. The XsltArgumentList provides additional run-time arguments.

Transform(IXPathNavigable, XsltArgumentList, Stream) Transform(IXPathNavigable, XsltArgumentList, Stream) Transform(IXPathNavigable, XsltArgumentList, Stream) Transform(IXPathNavigable, XsltArgumentList, Stream)

Executes the transform using the input document specified by the IXPathNavigable object and outputs the results to a stream. The XsltArgumentList provides additional runtime arguments.

Transform(XmlReader, XsltArgumentList, XmlWriter) Transform(XmlReader, XsltArgumentList, XmlWriter) Transform(XmlReader, XsltArgumentList, XmlWriter) Transform(XmlReader, XsltArgumentList, XmlWriter)

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.

Transform(XmlReader, XsltArgumentList, Stream) Transform(XmlReader, XsltArgumentList, Stream) Transform(XmlReader, XsltArgumentList, Stream) Transform(XmlReader, XsltArgumentList, Stream)

Executes the transform using the input document specified by the XmlReader object and outputs the results to a stream. The XsltArgumentList provides additional run-time arguments.

Transform(String, String) Transform(String, String) Transform(String, String) Transform(String, String)

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

Transform(String, XsltArgumentList, TextWriter) Transform(String, XsltArgumentList, TextWriter) Transform(String, XsltArgumentList, TextWriter) Transform(String, XsltArgumentList, TextWriter)

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

Transform(String, XsltArgumentList, Stream) Transform(String, XsltArgumentList, Stream) Transform(String, XsltArgumentList, Stream) Transform(String, XsltArgumentList, Stream)

Executes the transform using the input document specified by the URI and outputs the results to stream. The XsltArgumentList provides additional run-time arguments.

Transform(IXPathNavigable, XmlWriter) Transform(IXPathNavigable, XmlWriter) Transform(IXPathNavigable, XmlWriter) Transform(IXPathNavigable, XmlWriter)

Executes the transform using the input document specified by the IXPathNavigable object and outputs the results to an XmlWriter.

Transform(XmlReader, XmlWriter) Transform(XmlReader, XmlWriter) Transform(XmlReader, XmlWriter) Transform(XmlReader, XmlWriter)

Executes the transform using the input document specified by the XmlReader object and outputs the results to an XmlWriter.

Transform(String, XmlWriter) Transform(String, XmlWriter) Transform(String, XmlWriter) Transform(String, XmlWriter)

Executes the transform using the input document specified by the URI and outputs the results to an XmlWriter.

Transform(XmlReader, XsltArgumentList, XmlWriter, XmlResolver) Transform(XmlReader, XsltArgumentList, XmlWriter, XmlResolver) Transform(XmlReader, XsltArgumentList, XmlWriter, XmlResolver) Transform(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.

Transform(String, XsltArgumentList, XmlWriter) Transform(String, XsltArgumentList, XmlWriter) Transform(String, XsltArgumentList, XmlWriter) Transform(String, XsltArgumentList, XmlWriter)

Executes the transform using the input document specified by the URI and outputs the results to an XmlWriter. The XsltArgumentList provides additional run-time arguments.

Transform(IXPathNavigable, XsltArgumentList, XmlWriter, XmlResolver) Transform(IXPathNavigable, XsltArgumentList, XmlWriter, XmlResolver) Transform(IXPathNavigable, XsltArgumentList, XmlWriter, XmlResolver) Transform(IXPathNavigable, XsltArgumentList, XmlWriter, XmlResolver)

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

Remarks

Note

There are differences between XSLT compiled in Debug mode and XSLT compiled in Release mode. In some situations, style sheets compiled in Debug mode will not throw errors during Load, but will later fail during Transform. The same style sheet compiled in Release mode will fail during Load. An example of such behavior is when a variable that is not of a node-set type is assigned to an expression where a node-set is required.

Transform(XmlReader, XsltArgumentList, TextWriter) Transform(XmlReader, XsltArgumentList, TextWriter) Transform(XmlReader, XsltArgumentList, TextWriter) Transform(XmlReader, XsltArgumentList, TextWriter)

Executes the transform using the input document specified by the XmlReader object and outputs the results to a TextWriter. The XsltArgumentList provides additional run-time arguments.

public:
 void Transform(System::Xml::XmlReader ^ input, System::Xml::Xsl::XsltArgumentList ^ arguments, System::IO::TextWriter ^ results);
public void Transform (System.Xml.XmlReader input, System.Xml.Xsl.XsltArgumentList arguments, System.IO.TextWriter results);
member this.Transform : System.Xml.XmlReader * System.Xml.Xsl.XsltArgumentList * System.IO.TextWriter -> unit
Public Sub Transform (input As XmlReader, arguments As XsltArgumentList, results As TextWriter)

Parameters

input
XmlReader XmlReader XmlReader XmlReader

An XmlReader containing the input document.

arguments
XsltArgumentList XsltArgumentList XsltArgumentList XsltArgumentList

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

results
TextWriter TextWriter TextWriter TextWriter

The TextWriter to which you want to output.

Exceptions

There was an error executing the XSLT transform.

Remarks

If the style sheet includes an XSLT document() function, it is resolved using an XmlUrlResolver with no user credentials. If the external resource is 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.

See also

Transform(IXPathNavigable, XsltArgumentList, XmlWriter) Transform(IXPathNavigable, XsltArgumentList, XmlWriter) Transform(IXPathNavigable, XsltArgumentList, XmlWriter) Transform(IXPathNavigable, XsltArgumentList, XmlWriter)

Executes the transform using the input document specified by the IXPathNavigable object and outputs the results to an XmlWriter. The XsltArgumentList provides additional run-time arguments.

public:
 void Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::Xsl::XsltArgumentList ^ arguments, System::Xml::XmlWriter ^ results);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList arguments, System.Xml.XmlWriter results);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlWriter -> unit
Public Sub Transform (input As IXPathNavigable, arguments As XsltArgumentList, results As XmlWriter)

Parameters

input
IXPathNavigable IXPathNavigable IXPathNavigable IXPathNavigable

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

arguments
XsltArgumentList XsltArgumentList XsltArgumentList XsltArgumentList

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

results
XmlWriter XmlWriter XmlWriter 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.

Exceptions

There was an error executing the XSLT transform.

Remarks

If the XSLT document() function is enabled, it is resolved using an XmlUrlResolver with no user credentials. If the external resource is 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.

This method does not support the xsl:strip-space element. If your compiled style sheet included the xsl:strip-space element, you must use the Transform overload which takes an XmlReader as the input argument.

The IXPathNavigable interface is implemented in the XmlNode and XPathDocument classes. These classes represent an in-memory cache of XML data.

  • The XmlNode class is based on the W3C Document Object Model (DOM) and includes editing capabilities.

  • The XPathDocument class is a read-only data store based on the XPath data model. XPathDocument is the recommended class for XSLT processing. It provides faster performance when compared to the XmlNode class.

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 object containing just the node fragment, and pass that object to the Transform method. For more information, see How to: Transform a Node Fragment.

See also

Transform(IXPathNavigable, XsltArgumentList, TextWriter) Transform(IXPathNavigable, XsltArgumentList, TextWriter) Transform(IXPathNavigable, XsltArgumentList, TextWriter) Transform(IXPathNavigable, XsltArgumentList, TextWriter)

Executes the transform using the input document specified by the IXPathNavigable object and outputs the results to an TextWriter. The XsltArgumentList provides additional run-time arguments.

public:
 void Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::Xsl::XsltArgumentList ^ arguments, System::IO::TextWriter ^ results);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList arguments, System.IO.TextWriter results);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.IO.TextWriter -> unit
Public Sub Transform (input As IXPathNavigable, arguments As XsltArgumentList, results As TextWriter)

Parameters

input
IXPathNavigable IXPathNavigable IXPathNavigable IXPathNavigable

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

arguments
XsltArgumentList XsltArgumentList XsltArgumentList XsltArgumentList

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

results
TextWriter TextWriter TextWriter TextWriter

The TextWriter to which you want to output.

Exceptions

There was an error executing the XSLT transform.

Remarks

If the XSLT document() function is enabled, it is resolved using an XmlUrlResolver with no user credentials. If the external resource is 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.

This method does not support the xsl:strip-space element. If your compiled style sheet included the xsl:strip-space element, you must use the Transform overload which takes an XmlReader as the input argument.

The IXPathNavigable interface is implemented in the XmlNode and XPathDocument classes. These classes represent an in-memory cache of XML data.

  • The XmlNode class is based on the W3C Document Object Model (DOM) and includes editing capabilities.

  • The XPathDocument class is a read-only data store based on the XPath data model. XPathDocument is the recommended class for XSLT processing. It provides faster performance when compared to the XmlNode class.

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 object containing just the node fragment, and pass that object to the Transform method. For more information, see How to: Transform a Node Fragment.

See also

Transform(IXPathNavigable, XsltArgumentList, Stream) Transform(IXPathNavigable, XsltArgumentList, Stream) Transform(IXPathNavigable, XsltArgumentList, Stream) Transform(IXPathNavigable, XsltArgumentList, Stream)

Executes the transform using the input document specified by the IXPathNavigable object and outputs the results to a stream. The XsltArgumentList provides additional runtime arguments.

public:
 void Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::Xsl::XsltArgumentList ^ arguments, System::IO::Stream ^ results);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList arguments, System.IO.Stream results);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.IO.Stream -> unit
Public Sub Transform (input As IXPathNavigable, arguments As XsltArgumentList, results As Stream)

Parameters

input
IXPathNavigable IXPathNavigable IXPathNavigable IXPathNavigable

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

arguments
XsltArgumentList XsltArgumentList XsltArgumentList XsltArgumentList

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

results
Stream Stream Stream Stream

The stream to which you want to output.

Exceptions

There was an error executing the XSLT transform.

Examples

The following example executes an XSLT transformation and outputs to a FileStream.

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

// Create the FileStream.
using (FileStream fs = new FileStream(@"c:\data\output.xml", FileMode.Create))
{
   // Execute the transformation.
   xslt.Transform(new XPathDocument("books.xml"), null, fs);
}
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load("output.xsl")
        
' Create the FileStream.
Using fs As New FileStream("c:\data\output.xml", FileMode.Create)
   ' Execute the transformation.
    xslt.Transform(New XPathDocument("books.xml"), Nothing, fs)
End Using

Remarks

If the XSLT document() function is enabled, it is resolved using an XmlUrlResolver with no user credentials. If the external resource is 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.

This method does not support the xsl:strip-space element. If your compiled style sheet included the xsl:strip-space element, you must use the Transform overload which takes an XmlReader as the input argument.

The IXPathNavigable interface is implemented in the XmlNode and XPathDocument classes. These classes represent an in-memory cache of XML data.

  • The XmlNode class is based on the W3C Document Object Model (DOM) and includes editing capabilities.

  • The XPathDocument class is a read-only data store based on the XPath data model. XPathDocument is the recommended class for XSLT processing. It provides faster performance when compared to the XmlNode class.

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 object containing just the node fragment, and pass that object to the Transform method. For more information, see How to: Transform a Node Fragment.

See also

Transform(XmlReader, XsltArgumentList, XmlWriter) Transform(XmlReader, XsltArgumentList, XmlWriter) Transform(XmlReader, XsltArgumentList, XmlWriter) Transform(XmlReader, XsltArgumentList, XmlWriter)

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.

public:
 void Transform(System::Xml::XmlReader ^ input, System::Xml::Xsl::XsltArgumentList ^ arguments, System::Xml::XmlWriter ^ results);
public void Transform (System.Xml.XmlReader input, System.Xml.Xsl.XsltArgumentList arguments, System.Xml.XmlWriter results);
member this.Transform : System.Xml.XmlReader * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlWriter -> unit
Public Sub Transform (input As XmlReader, arguments As XsltArgumentList, results As XmlWriter)

Parameters

input
XmlReader XmlReader XmlReader XmlReader

An XmlReader containing the input document.

arguments
XsltArgumentList XsltArgumentList XsltArgumentList XsltArgumentList

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

results
XmlWriter XmlWriter XmlWriter 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.

Exceptions

There was an error executing the XSLT transform.

Remarks

If the style sheet includes an XSLT document() function, it is resolved using an XmlUrlResolver with no user credentials. If the external resource is 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.

See also

Transform(XmlReader, XsltArgumentList, Stream) Transform(XmlReader, XsltArgumentList, Stream) Transform(XmlReader, XsltArgumentList, Stream) Transform(XmlReader, XsltArgumentList, Stream)

Executes the transform using the input document specified by the XmlReader object and outputs the results to a stream. The XsltArgumentList provides additional run-time arguments.

public:
 void Transform(System::Xml::XmlReader ^ input, System::Xml::Xsl::XsltArgumentList ^ arguments, System::IO::Stream ^ results);
public void Transform (System.Xml.XmlReader input, System.Xml.Xsl.XsltArgumentList arguments, System.IO.Stream results);
member this.Transform : System.Xml.XmlReader * System.Xml.Xsl.XsltArgumentList * System.IO.Stream -> unit
Public Sub Transform (input As XmlReader, arguments As XsltArgumentList, results As Stream)

Parameters

input
XmlReader XmlReader XmlReader XmlReader

An XmlReader containing the input document.

arguments
XsltArgumentList XsltArgumentList XsltArgumentList XsltArgumentList

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

results
Stream Stream Stream Stream

The stream to which you want to output.

Exceptions

There was an error executing the XSLT transform.

Remarks

If the style sheet includes an XSLT document() function, it is resolved using an XmlUrlResolver with no user credentials. If the external resource is 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.

See also

Transform(String, String) Transform(String, String) Transform(String, String) Transform(String, String)

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

public:
 void Transform(System::String ^ inputUri, System::String ^ resultsFile);
public void Transform (string inputUri, string resultsFile);
member this.Transform : string * string -> unit
Public Sub Transform (inputUri As String, resultsFile As String)

Parameters

inputUri
String String String String

The URI of the input document.

resultsFile
String String String String

The URI of the output file.

Exceptions

There was an error executing the XSLT transform.

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

The inputUri or resultsFile value cannot be resolved.

-or-

An error occurred while processing the request

inputUri or resultsFile is not a valid URI.

There was a parsing error loading the input document.

Examples

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

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

// Execute the transform and output the results to a file.
xslt.Transform("books.xml", "books.html");
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load("output.xsl")
        
' Execute the transform and output the results to a file.
xslt.Transform("books.xml", "books.html")

The sample uses the following two input files:

books.xml

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

output.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="bookstore">
  <HTML>
    <BODY>
      <TABLE BORDER="2">
        <TR>
          <TD>ISBN</TD>
          <TD>Title</TD>
          <TD>Price</TD>
        </TR>
        <xsl:apply-templates select="book"/>
      </TABLE>
    </BODY>
  </HTML>
</xsl:template>
<xsl:template match="book">
  <TR>
    <TD><xsl:value-of select="@ISBN"/></TD>
    <TD><xsl:value-of select="title"/></TD>
    <TD><xsl:value-of select="price"/></TD>
  </TR>
</xsl:template>
</xsl:stylesheet>

Remarks

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.

See also

Transform(String, XsltArgumentList, TextWriter) Transform(String, XsltArgumentList, TextWriter) Transform(String, XsltArgumentList, TextWriter) Transform(String, XsltArgumentList, TextWriter)

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

public:
 void Transform(System::String ^ inputUri, System::Xml::Xsl::XsltArgumentList ^ arguments, System::IO::TextWriter ^ results);
public void Transform (string inputUri, System.Xml.Xsl.XsltArgumentList arguments, System.IO.TextWriter results);
member this.Transform : string * System.Xml.Xsl.XsltArgumentList * System.IO.TextWriter -> unit
Public Sub Transform (inputUri As String, arguments As XsltArgumentList, results As TextWriter)

Parameters

inputUri
String String String String

The URI of the input document.

arguments
XsltArgumentList XsltArgumentList XsltArgumentList XsltArgumentList

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

results
TextWriter TextWriter TextWriter TextWriter

The TextWriter to which you want to output.

Exceptions

There was an error executing the XSLT transform.

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

The inputUri value cannot be resolved.

-or-

An error occurred while processing the request

There was a parsing error loading the input document.

Examples

The following example executes an XSLT transformation and outputs a string.

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

// Transform the file and output an HTML string.
string HTMLoutput;
StringWriter writer = new StringWriter();
xslt.Transform("books.xml", null, writer);
HTMLoutput = writer.ToString();
writer.Close();
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load("HTML_out.xsl")
        
' Transform the file and output an HTML string.
Dim HTMLoutput As String
Dim writer As New StringWriter()
xslt.Transform("books.xml", Nothing, writer)
HTMLoutput = writer.ToString()
writer.Close()

Remarks

This method uses a default XmlUrlResolver with no user credentials to resolve the input document and any instances of the XSLT document() function found in the style sheet. 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.

See also

Transform(String, XsltArgumentList, Stream) Transform(String, XsltArgumentList, Stream) Transform(String, XsltArgumentList, Stream) Transform(String, XsltArgumentList, Stream)

Executes the transform using the input document specified by the URI and outputs the results to stream. The XsltArgumentList provides additional run-time arguments.

public:
 void Transform(System::String ^ inputUri, System::Xml::Xsl::XsltArgumentList ^ arguments, System::IO::Stream ^ results);
public void Transform (string inputUri, System.Xml.Xsl.XsltArgumentList arguments, System.IO.Stream results);
member this.Transform : string * System.Xml.Xsl.XsltArgumentList * System.IO.Stream -> unit
Public Sub Transform (inputUri As String, arguments As XsltArgumentList, results As Stream)

Parameters

inputUri
String String String String

The URI of the input document.

arguments
XsltArgumentList XsltArgumentList XsltArgumentList XsltArgumentList

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

results
Stream Stream Stream Stream

The stream to which you want to output.

Exceptions

There was an error executing the XSLT transform.

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

The inputUri value cannot be resolved.

-or-

An error occurred while processing the request

There was a parsing error loading the input document.

Remarks

This method uses a default XmlUrlResolver with no user credentials to resolve the input document and any instances of the XSLT document() function found in the style sheet. 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.

See also

Transform(IXPathNavigable, XmlWriter) Transform(IXPathNavigable, XmlWriter) Transform(IXPathNavigable, XmlWriter) Transform(IXPathNavigable, XmlWriter)

Executes the transform using the input document specified by the IXPathNavigable object and outputs the results to an XmlWriter.

public:
 void Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::XmlWriter ^ results);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.XmlWriter results);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.XmlWriter -> unit
Public Sub Transform (input As IXPathNavigable, results As XmlWriter)

Parameters

input
IXPathNavigable IXPathNavigable IXPathNavigable IXPathNavigable

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

results
XmlWriter XmlWriter XmlWriter 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.

Exceptions

There was an error executing the XSLT transform.

Examples

The following example executes an XSLT transformation and outputs to an XmlWriter object.

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

// Create the writer.
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = "\t";
XmlWriter writer = XmlWriter.Create("output.xml", settings);

// Execute the transformation.
xslt.Transform(new XPathDocument("books.xml"), writer);
writer.Close();
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load("output.xsl")
        
' Create the writer.
Dim settings As New XmlWriterSettings()
settings.Indent = True
settings.IndentChars = vbTab
Dim writer As XmlWriter = XmlWriter.Create("output.xml", settings)
        
' Execute the transformation.
xslt.Transform(New XPathDocument("books.xml"), writer)
writer.Close()

Remarks

If the XSLT document() function is enabled, it is resolved using an XmlUrlResolver with no user credentials. If the external resource is 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.

This method does not support the xsl:strip-space element. If your compiled style sheet included the xsl:strip-space element, you must use the Transform overload which takes an XmlReader as the input argument.

The IXPathNavigable interface is implemented in the XmlNode and XPathDocument classes. These classes represent an in-memory cache of XML data.

  • The XmlNode class is based on the W3C Document Object Model (DOM) and includes editing capabilities.

  • The XPathDocument class is a read-only data store based on the XPath data model. XPathDocument is the recommended class for XSLT processing. It provides faster performance when compared to the XmlNode class.

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 object containing just the node fragment, and pass that object to the Transform method. For more information, see How to: Transform a Node Fragment.

See also

Transform(XmlReader, XmlWriter) Transform(XmlReader, XmlWriter) Transform(XmlReader, XmlWriter) Transform(XmlReader, XmlWriter)

Executes the transform using the input document specified by the XmlReader object and outputs the results to an XmlWriter.

public:
 void Transform(System::Xml::XmlReader ^ input, System::Xml::XmlWriter ^ results);
public void Transform (System.Xml.XmlReader input, System.Xml.XmlWriter results);
member this.Transform : System.Xml.XmlReader * System.Xml.XmlWriter -> unit
Public Sub Transform (input As XmlReader, results As XmlWriter)

Parameters

input
XmlReader XmlReader XmlReader XmlReader

The XmlReader containing the input document.

results
XmlWriter XmlWriter XmlWriter 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.

Exceptions

There was an error executing the XSLT transform.

Examples

The following example transforms the first book in the books.xml file.

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

// Create the writer.
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = "\t";
XmlWriter writer = XmlWriter.Create("output.xml", settings);

XmlReader reader = XmlReader.Create("books.xml");
reader.MoveToContent();

// Execute the transformation.
xslt.Transform(reader, writer);
writer.Close();
reader.Close();
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load("output.xsl")
        
' Create the writer.
Dim settings As New XmlWriterSettings()
settings.Indent = True
settings.IndentChars = vbTab
Dim writer As XmlWriter = XmlWriter.Create("output.xml", settings)
        
Dim reader As XmlReader = XmlReader.Create("books.xml")
reader.MoveToContent()
        
' Execute the transformation.
xslt.Transform(reader, writer)
writer.Close()
reader.Close()

Remarks

If the XSLT document() function is enabled, it is resolved using an XmlUrlResolver with no user credentials. If the external resource is 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.

See also

Transform(String, XmlWriter) Transform(String, XmlWriter) Transform(String, XmlWriter) Transform(String, XmlWriter)

Executes the transform using the input document specified by the URI and outputs the results to an XmlWriter.

public:
 void Transform(System::String ^ inputUri, System::Xml::XmlWriter ^ results);
public void Transform (string inputUri, System.Xml.XmlWriter results);
member this.Transform : string * System.Xml.XmlWriter -> unit
Public Sub Transform (inputUri As String, results As XmlWriter)

Parameters

inputUri
String String String String

The URI of the input document.

results
XmlWriter XmlWriter XmlWriter 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.

Exceptions

There was an error executing the XSLT transform.

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

The inputUri value cannot be resolved.

-or-

An error occurred while processing the request.

There was a parsing error loading the input document.

Examples

The following example executes an XSLT transformation and outputs to an XmlWriter object.

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

// Create the writer.
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = "\t";
XmlWriter writer = XmlWriter.Create("output.xml", settings);

// Execute the transformation.
xslt.Transform("books.xml", writer);
writer.Close();
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load("output.xsl")
        
' Create the writer.
Dim settings As New XmlWriterSettings()
settings.Indent = True
settings.IndentChars = vbTab
Dim writer As XmlWriter = XmlWriter.Create("output.xml", settings)
        
' Execute the transformation.
xslt.Transform("books.xml", writer)
writer.Close()

Remarks

This method uses a default XmlUrlResolver with no user credentials to resolve the input document and any instances of the XSLT document() function found in the style sheet. 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.

This method does not support the xsl:strip-space element. If your compiled style sheet included the xsl:strip-space element, you must use the Transform overload which takes an XmlReader as the input argument.

See also

Transform(XmlReader, XsltArgumentList, XmlWriter, XmlResolver) Transform(XmlReader, XsltArgumentList, XmlWriter, XmlResolver) Transform(XmlReader, XsltArgumentList, XmlWriter, XmlResolver) Transform(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.

public:
 void Transform(System::Xml::XmlReader ^ input, System::Xml::Xsl::XsltArgumentList ^ arguments, System::Xml::XmlWriter ^ results, System::Xml::XmlResolver ^ documentResolver);
public void Transform (System.Xml.XmlReader input, System.Xml.Xsl.XsltArgumentList arguments, System.Xml.XmlWriter results, System.Xml.XmlResolver documentResolver);
member this.Transform : System.Xml.XmlReader * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlWriter * System.Xml.XmlResolver -> unit
Public Sub Transform (input As XmlReader, arguments As XsltArgumentList, results As XmlWriter, documentResolver As XmlResolver)

Parameters

input
XmlReader XmlReader XmlReader XmlReader

An XmlReader containing the input document.

arguments
XsltArgumentList XsltArgumentList XsltArgumentList XsltArgumentList

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

results
XmlWriter XmlWriter XmlWriter 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.

documentResolver
XmlResolver XmlResolver XmlResolver XmlResolver

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

Exceptions

There was an error executing the XSLT transform.

Examples

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);
   }
}
' Create a resolver and specify the necessary credentials.
Dim resolver As New XmlSecureResolver(New XmlUrlResolver(), "http://serverName/data/")
Dim myCred As System.Net.NetworkCredential
myCred = New System.Net.NetworkCredential(UserName, SecurelyStoredPassword, Domain)
resolver.Credentials = myCred
        
Dim settings As New XsltSettings()
settings.EnableDocumentFunction = True
        
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load("http://serverName/data/xsl/sort.xsl", settings, resolver)
        
' Transform the file.
        Using reader As XmlReader = XmlReader.Create("books.xml")

            Using writer As XmlWriter = XmlWriter.Create("output.xml")
                xslt.Transform(reader, Nothing, writer, resolver)
            End Using

        End Using
See also

Transform(String, XsltArgumentList, XmlWriter) Transform(String, XsltArgumentList, XmlWriter) Transform(String, XsltArgumentList, XmlWriter) Transform(String, XsltArgumentList, XmlWriter)

Executes the transform using the input document specified by the URI and outputs the results to an XmlWriter. The XsltArgumentList provides additional run-time arguments.

public:
 void Transform(System::String ^ inputUri, System::Xml::Xsl::XsltArgumentList ^ arguments, System::Xml::XmlWriter ^ results);
public void Transform (string inputUri, System.Xml.Xsl.XsltArgumentList arguments, System.Xml.XmlWriter results);
member this.Transform : string * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlWriter -> unit
Public Sub Transform (inputUri As String, arguments As XsltArgumentList, results As XmlWriter)

Parameters

inputUri
String String String String

The URI of the input document.

arguments
XsltArgumentList XsltArgumentList XsltArgumentList XsltArgumentList

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

results
XmlWriter XmlWriter XmlWriter 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.

Exceptions

There was an error executing the XSLT transform.

The inputtUri value includes a filename or directory cannot be found.

The inputUri value cannot be resolved.

-or-

An error occurred while processing the request.

There was a parsing error loading the input document.

Examples

The following example uses an XsltArgumentList object to create a parameter representing the current date and time.

using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;

public class Sample
{

    public static void Main()
    {

        // Create the XslCompiledTransform and load the stylesheet.
        XslCompiledTransform xslt = new XslCompiledTransform();
        xslt.Load("order.xsl");

        // Create the XsltArgumentList.
        XsltArgumentList xslArg = new XsltArgumentList();

        // Create a parameter which represents the current date and time.
        DateTime d = DateTime.Now;
        xslArg.AddParam("date", "", d.ToString());

        // Transform the file.
        using (XmlWriter w = XmlWriter.Create("output.xml"))
        {
            xslt.Transform("order.xml", xslArg, w);
        }
    }
}
Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Xsl

Public Class Sample

    Public Shared Sub Main()

        ' Create the XslCompiledTransform and load the stylesheet.
        Dim xslt As New XslCompiledTransform()
        xslt.Load("order.xsl")

        ' Create the XsltArgumentList.
        Dim xslArg As New XsltArgumentList()

        ' Create a parameter which represents the current date and time.
        Dim d As DateTime = DateTime.Now
        xslArg.AddParam("date", "", d.ToString())

        Using w As XmlWriter = XmlWriter.Create("output.xml")
            ' Transform the file.
            xslt.Transform("order.xml", xslArg, w)
        End Using

    End Sub 'Main 
End Class 'Sample

The example uses the following two data files as input.

order.xml

<!--Represents a customer order-->
<order>
  <book ISBN='10-861003-324'>
    <title>The Handmaid's Tale</title>
    <price>19.95</price>
  </book>
  <cd ISBN='2-3631-4'>
    <title>Americana</title>
    <price>16.95</price>
  </cd>
</order>

order.xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:param name="date"/>
  <xsl:template match="/">
    <order>
      <date><xsl:value-of select="$date"/></date>
      <total><xsl:value-of select="sum(//price)"/></total>
    </order>
  </xsl:template>
</xsl:stylesheet>

Remarks

This method uses a default XmlUrlResolver with no user credentials to resolve the input document and any instances of the XSLT document() function found in the style sheet. 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.

See also

Transform(IXPathNavigable, XsltArgumentList, XmlWriter, XmlResolver) Transform(IXPathNavigable, XsltArgumentList, XmlWriter, XmlResolver) Transform(IXPathNavigable, XsltArgumentList, XmlWriter, XmlResolver) Transform(IXPathNavigable, XsltArgumentList, XmlWriter, XmlResolver)

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

public:
 void Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::Xsl::XsltArgumentList ^ arguments, System::Xml::XmlWriter ^ results, System::Xml::XmlResolver ^ documentResolver);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList arguments, System.Xml.XmlWriter results, System.Xml.XmlResolver documentResolver);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlWriter * System.Xml.XmlResolver -> unit
Public Sub Transform (input As IXPathNavigable, arguments As XsltArgumentList, results As XmlWriter, documentResolver As XmlResolver)

Parameters

input
IXPathNavigable IXPathNavigable IXPathNavigable IXPathNavigable

The document to transform that is specified by the IXPathNavigable object.

results
XmlWriter XmlWriter XmlWriter XmlWriter

The XmlWriter to which you want to output.

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

documentResolver
XmlResolver XmlResolver XmlResolver XmlResolver

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

Applies to