XslCompiledTransform.Transform Method (IXPathNavigable, XmlWriter)
Assembly: System.Xml (in System.Xml.dll)
- Type: System.Xml.XPath.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.
- 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.
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 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.
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();
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.