Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

XslTransform.Transform Method (XPathNavigator, XsltArgumentList, XmlWriter, XmlResolver)

Transforms the XML data in the XPathNavigator using the specified args and outputs the result to an XmlWriter.

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

public void Transform(
	XPathNavigator input,
	XsltArgumentList args,
	XmlWriter output,
	XmlResolver resolver
)

Parameters

input
Type: System.Xml.XPath.XPathNavigator

An XPathNavigator containing the data to be transformed.

args
Type: System.Xml.Xsl.XsltArgumentList

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

output
Type: System.Xml.XmlWriter

The XmlWriter to which you want to output.

resolver
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.

ExceptionCondition
InvalidOperationException

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.

NoteNote

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= http://www.w3.org/1999/XSL/Transform.

The args are matched with the xsl:param elements defined in the style sheet. The transformation selections apply to the document as a whole. In other words, if the current node is set on a node tree other than the document root node, this does not prevent the transformation process from accessing all nodes in the loaded document. After the transformation is performed, the XPathNavigator remains in its original state. This means that the node, that is current before the transformation process, remains the current node after the Transform method has been called.

The xsl:output element is not supported when outputting to an XmlWriter (xsl:output is ignored). See Outputs from an XslTransform for more information.

The following example loads and edits an XML document before performing an XSLT transform.

XmlDocument doc = new XmlDocument();
doc.Load("books.xml");

// Modify the XML file.
XmlElement root = doc.DocumentElement;
root.FirstChild.LastChild.InnerText = "12.95";

// Create an XPathNavigator to use for the transform.
XPathNavigator nav = root.CreateNavigator();

// Transform the file.
XslTransform xslt = new XslTransform();
xslt.Load("output.xsl");
XmlTextWriter writer = new XmlTextWriter("books.html", null);
xslt.Transform(nav, null, writer, null);

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft