title: Transforming an xml file using xslt with XslCompiledTransform in C#
body: <p>I have an xml file and two xslt files say list.xslt and Style.xslt. The  style.xslt has some css styles and it is called from List.xslt using the import statement from the List.xslt</p>
  
  <pre><code> &lt;xsl:include href="Style.xslt"/&gt;
  </code></pre>
  
  <p>Below is the code which I use to transform the xml :</p>
  
  <pre><code>            StringWriter sb = new StringWriter();
  
              XmlWriterSettings settings = new XmlWriterSettings();
              settings.OmitXmlDeclaration = true;
              settings.ConformanceLevel = ConformanceLevel.Fragment;
              settings.CloseOutput = false;
  
              // Create the XmlWriter object and write some content.
              MemoryStream strm = new MemoryStream();
              XmlWriter xmlWriter = XmlWriter.Create(sb, settings);
  
              //Resolve the url for xslt files
              XmlUrlResolver resolver = new MyXmlUrlResolver();
              resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
  
              XslCompiledTransform transform = new XslCompiledTransform();
  
              XPathDocument xpathDoc = new XPathDocument(Server.MapPath("App_Data/Test.xml"));
              string xslPath = Server.MapPath("App_Data/List.xslt");
  
              transform.Load(xslPath, null, resolver);
              transform.Transform(xpathDoc, null, xmlWriter, resolver);
              Response.Write(sb.ToString());
  </code></pre>
  
  <p>I use UrlResolver to resolve the correct path as below</p>
  
  <pre><code>public override Uri ResolveUri(Uri baseUri, string relativeUri)
          {
              if (baseUri != null)
                  return base.ResolveUri(baseUri, relativeUri);
              else
                  return base.ResolveUri(new Uri("http://localhost:54090/"), relativeUri);    
          }
  </code></pre>
  
  <p>My problem is, when I use XslCompiledTransform, the browser is not rendering the styles defined in the style.xslt . But I guess the application is able to access the style.xslt file as I am not getting any file not found error.</p>
  
  <p>Can any body please advise what I am doing wrong here?</p>
  
  <p>Note:- Everything works fine when I use the below method of xslt transforming in browser (not using server side) instead of XslCompiledTransform:</p>
  
  <pre><code>&lt;?xml version = "1.0" encoding = "UTF-8" ?&gt;
  &lt;?xml-stylesheet type ="text/xsl" href="List.xslt" ?&gt;
  &lt;data&gt;
  .
  .
  &lt;/data&gt;
  </code></pre>