title: Is XslCompiledTransform to blame for slow XML transformation for a large file?
body: <p>I am very new to XSLT, and the first thing that i need to do is parse a 300MB file (and that's on the small end). The XSLT is not that complex for the moment, it's just removing some nodes that match a certain criteria. 
  I have two problems:</p>
  
  <ol>
  <li>It's too slow. It takes 50 seconds to process 500,000 records and that's not fast enough. </li>
  <li>It consumes 500MBs of memory, so this will only get worse when the files will get bigger. </li>
  </ol>
  
  <p>Is there anything i can do natively in .net to make is perform better?</p>
  
  <p>I know I can look into SAX based parsing, or STX (which is mentioned in <a href="https://stackoverflow.com/questions/1690194/xslt-transformations-on-very-large-files">another post</a>), but I would prefer to stay within the .net boundaries. </p>
  
  <p>Thank you!</p>
  
  <p>EDIT:
  Here's my XSLT</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:test="http://schemas...."&gt;
   &lt;xsl:output omit-xml-declaration="yes"/&gt;
      &lt;xsl:template match="node()|@*"&gt;
        &lt;xsl:copy&gt;
           &lt;xsl:apply-templates select="node()|@*"/&gt;
        &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="test:QueryRow[test:Columns/test:QueryColumn[test:Name='hit_count' and test:Value&gt;200]]"/&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Here's the code i use to do the transform</p>
  
  <pre><code>XslCompiledTransform compiledTransform = new XslCompiledTransform();
  XsltSettings settings = new XsltSettings();
  settings.EnableScript = true;
  XmlReader xmlReader = XmlReader.Create("in.xml");
  XmlWriter xmlWriter = XmlWriter.Create("out.xml");
  compiledTransform.Load("format.xslt", settings, null);
  compiledTransform.Transform(xmlReader, xmlWriter); //this is what takes a long time
  </code></pre>
  
  <p>At the moment I am trying to just read the file in, and write it back out, but it seems to actually be reading the whole file into memory, so I am trying to find a way to read it line by line. </p>