FIX: 'XSLT compile error' on host-named site collection

Scenario:
On your host-named site collection you are trying to reference an XSLT file hosted in a SharePoint Library.
Assuming you have already checked that the xslt file is where it is expected to be.

Your code could look like this:

XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = CredentialCache.DefaultCredentials;

XmlTextReader stylesheet = new XmlTextReader(xslLink);
stylesheet.XmlResolver = resolver;

XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(stylesheet);

On the last line you are getting this error:
XSLT compile error.
   at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader, Boolean include)
   at System.Xml.Xsl.Xslt.XsltLoader.Load(Compiler compiler, Object stylesheet, XmlResolver xmlResolver)
   at System.Xml.Xsl.Xslt.Compiler.Compile(Object stylesheet, XmlResolver xmlResolver, QilExpression& qil)
   at System.Xml.Xsl.XslCompiledTransform.CompileXsltToQil(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
   at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
   at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet)

Fix:
On the SharePoint server, add the host-name and IP in the "hosts" file (%systemroot%\system32\drivers\etc\hosts). Your new entry should look like:
10.10.10.190 SharePointTest.microsoft.com 
10.10.10.190 is the server's public IP address
SharePointTest.microsoft.com is your site collection host-name

Cause:
SharePoint is trying to access the XSLT file using a URL like:
http://SharePointTest.microsoft.com/Styles/MyStyleFile.XSLT
and it cannot reach the named address http://SharePointTest.microsoft.com

Note: The change will not take effect immediately. You can wait a few minutes or try this command:
ipconfig /flushdns

Leave a Reply