title: White space cannot be stripped from input documents that have already been loaded. Provide the input document as an XmlReader instead
body: <p>I want to transform a XML document, but having a problem.</p>
  
  <p>My XSLT looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="iso-8859-1" ?&gt; 
  &lt;xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
      &lt;xsl:output method="html" /&gt; 
      &lt;xsl:strip-space elements="*" /&gt; 
  
      &lt;xsl:template match="/"&gt;
          &lt;xsl:apply-templates select="address" /&gt; 
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="address"&gt;
          &lt;xsl:value-of select="@street" /&gt; 
          &lt;xsl:value-of select="@housenr" /&gt; 
          &lt;xsl:value-of select="@zipcode" /&gt; 
          &lt;xsl:value-of select="@city" /&gt; 
          &lt;xsl:value-of select="@country" /&gt; 
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>And the XML document I want to transform looks like this:</p>
  
  <pre><code>&lt;address id="4" type="1" 
      typename="Postadres" 
      street="pak street" 
      housenr="420" 
      zipcode="42000" 
      city="Nill" 
      country="Lahore" 
      kix="" /&gt; 
  </code></pre>
  
  <p>Here is the code I've written:</p>
  
  <pre><code>public static string Transform(XmlDocument doc, XmlDocument stylesheet)
  {
      var transform = new System.Xml.Xsl.XslCompiledTransform();
      XmlDocument domOutput = new XmlDocument();
  
      stylesheet.PreserveWhitespace = false;
      transform.Load(stylesheet);    // compiled stylesheet
  
      MemoryStream oStream = new MemoryStream();
      var writer = new System.IO.StringWriter();
  
      transform.Transform(doc, (XsltArgumentList)null, oStream);
  
      domOutput.Load(oStream);
  
      return writer.ToString();
  }
  </code></pre>
  
  <p>The following line throws an exception</p>
  
  <pre><code>transform.Transform(doc, (XsltArgumentList)null, oStream);
  </code></pre>
  
  <p>Exception message:</p>
  
  <blockquote>
    <p>White space cannot be stripped from input documents that have already been loaded. Provide the input document as an XmlReader instead.</p>
  </blockquote>
  
  <p>Can you tell me what I am doing wrong?</p>
  
  <p>Thanks in advance!</p>