title: XSLT transform creates StackoverflowException
body: <p>I tried to perform XSLT transform of a XSD file. My goal is in the end to create SQL from XSD. So far so good, this is what I have:</p>
  
  <pre><code>void Convert()
  {
              XPathDocument xpathDoc = new XPathDocument(@"myschema.xsd");
              string xslPath = @"convert.xsl";
              XslCompiledTransform transform = new XslCompiledTransform();               
              transform.Load(xslPath, new XsltSettings(true, true), null);    
              using (FileStream fs = File.Create(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "output.sql")))
              {
                  try
                  {
                      transform.Transform(xpathDoc, null, fs);
                  }
                  catch
                  {
                      fs.Close();
                  }
              }
  }
  </code></pre>
  
  <p>This is the XSLT file which is failing:</p>
  
  <pre><code>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 version="1.0" 
                 xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  
  &lt;!-- Get schema nodes from this schema and any included schemas --&gt;
  &lt;xsl:variable name="contents" select="/|document(//xs:include/@schemaLocation)" /&gt;
  
  &lt;xsl:template match="*" &gt;
  
   &lt;xsl:for-each select="$contents" &gt;
    &lt;xsl:apply-templates select=".//xs:element" /&gt;
   &lt;/xsl:for-each&gt;
  
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="xs:element"&gt;
  
      &lt;xsl:apply-templates /&gt;
  
  &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>I always get a StackoverflowException in System.Data.SqlXml.dll. How can I stop the recursion? Shouldn't it stop if no xs:element remain?</p>
  
  <p><strong>EDIT:</strong>
  The original code was from <a href="http://annlewkowicz.blogspot.com/2008/01/create-ddl-from-xsd-file-part-ii.html" rel="nofollow noreferrer">here</a> and it already had the error. I tried to fix it by simplifying the XSLT until only the error remained.</p>