title: C# How to perform a live xslt transformation on an in memory object?
body: <p>I have a function that takes 2 parameters : 1 = XML file, 2 = XSLT file, then performs a transformation and returns the resulting HTML.</p>
  
  <p>Here is the function:</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Will apply an XSLT style to any XML file and return the rendered HTML.
  /// &lt;/summary&gt;
  /// &lt;param name="xmlFileName"&gt;
  /// The file name of the XML document.
  /// &lt;/param&gt;
  /// &lt;param name="xslFileName"&gt;
  /// The file name of the XSL document.
  /// &lt;/param&gt;
  /// &lt;returns&gt;
  /// The rendered HTML.
  /// &lt;/returns&gt;
  public string TransformXml(string xmlFileName, string xslFileName)
  {
      var xtr = new XmlTextReader(xmlFileName)
                    {
                        WhitespaceHandling = WhitespaceHandling.None
                    };
      var xd = new XmlDocument();
      xd.Load(xtr);
  
      var xslt = new System.Xml.Xsl.XslCompiledTransform();
      xslt.Load(xslFileName);
      var stm = new MemoryStream();
      xslt.Transform(xd, null, stm);
      stm.Position = 1;
      var sr = new StreamReader(stm);
      xtr.Close();
      return sr.ReadToEnd();
  }
  </code></pre>
  
  <p>I want to change the function not to accept a file for the XML, but instead just an object. 
  The object is exactly compatible with the xslt, if it was serialized to file. But I don't want to have to serialize it to a file first. </p>
  
  <p>So to recap : keep the xslt coming from a file, but the xml input should an object I pass and would like to generate the xml from without any file system interaction. </p>