XslCompiledTransform.Transform Method (XmlReader, XmlWriter)
Namespace: System.Xml.Xsl
Assembly: System.Xml (in System.Xml.dll)
Parameters
- input
- Type: System.Xml.XmlReader
The XmlReader containing the input document.
- results
- 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.
| Exception | Condition |
|---|---|
| ArgumentNullException | The input or results value is null. |
| XsltException | There was an error executing the XSLT transform. |
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.
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();
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.