System.Xml.Xsl.XslTransform.Transform Method

Transforms the XML data in the System.Xml.XPath.IXPathNavigable using the specified args and outputs the result to a System.IO.Stream.

Syntax

public void Transform (System.Xml.XPath.IXPathNavigable input, XsltArgumentList args, System.IO.Stream output, System.Xml.XmlResolver resolver)

Parameters

input
An object implementing the System.Xml.XPath.IXPathNavigable interface. In the .NET Framework, this can be either an System.Xml.XmlNode (typically an System.Xml.XmlDocument), or an System.Xml.XPath.XPathDocument containing the data to be transformed.
args
An System.Xml.Xsl.XsltArgumentList containing the namespace-qualified arguments used as input to the transformation.
output
The stream to which you want to output.
resolver
The System.Xml.XmlResolver used to resolve the XSLT document() function. If this is null, the document() function is not resolved.

Remarks

Note:

The System.Xml.Xsl.XslTransform class is obsolete in the .NET Framework version 2.0. The System.Xml.Xsl.XslCompiledTransform class is the new XSLT processor. For more information, see Using the XslCompiledTransform Class and Migrating From the XslTransform Class.

System.Xml.Xsl.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.

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 System.Xml.XmlDocument containing just the node fragment and pass that System.Xml.XmlDocument to the XslTransform.Transform(System.Xml.XPath.IXPathNavigable, XsltArgumentList, System.IO.Stream, System.Xml.XmlResolver) method.

The following example performs a transformation on a node fragment.

Example

 XslTransform xslt = new XslTransform();     
 xslt.Load("print_root.xsl");
 XmlDocument doc = new XmlDocument();
 doc.Load("library.xml");
 // Create a new document containing just the node fragment.
 XmlNode testNode = doc.DocumentElement.FirstChild; 
 XmlDocument tmpDoc = new XmlDocument(); 
 tmpDoc.LoadXml(testNode.OuterXml);
 // Pass the document containing the node fragment 
 // to the Transform method.
 Console.WriteLine("Passing " + tmpDoc.OuterXml + " to print_root.xsl");
 xslt.Transform(tmpDoc, null, Console.Out, null);

The example uses the library.xml and print_root.xsl files as input and outputs the following to the console.

Example

 Passing <book genre="novel" ISBN="1-861001-57-5"><title>Pride And Prejudice</title></book> to print_root.xsl 
 Root node is book.

library.xml

Example

 <library>
   <book genre='novel' ISBN='1-861001-57-5'>
      <title>Pride And Prejudice</title>
   </book>
   <book genre='novel' ISBN='1-81920-21-2'>
      <title>Hook</title>
   </book>
 </library>

print_root.xsl

Example

 <style sheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform" >
   <output method="text" /> 
   <template match="/">
      Root node is  <value-of select="local-name(//*[position() = 1])" /> 
   </template>
 </style sheet>

Requirements

Namespace: System.Xml.Xsl
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0