Return to doc.sitecore.com

Valid for Sitecore 5.3
Is it possible to execute XSLT on a non-Sitecore site?

Q:

I’d like to get an HTML code of the XSLT rendering on a non-Sitecore site remotely. Is it possible to execute XSLT on a non-Sitecore site?

A:

To execute XSLT on a non-Sitecore site, you need to create the WebService which renders a given XSLT rendering and returns the HTML code. For example:

  1. In your current Sitecore project add a Web Service page (asmx) to the /layout folder with, for example, the following code:

1.  Sample code

using Sitecore;
using Sitecore.Web.UI.WebControls;
namespace _3_061102.layouts
{
  
/// <summary>
  
/// Summary description for WebService1
  
/// </summary>
  [WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo
= WsiProfiles.BasicProfile1_1)]
  [ToolboxItem(
false)]
  
public class WebService1 : System.Web.Services.WebService
  {
    [WebMethod]
    
public string ExecuteXslt(string XslFile)
    {
      XslFile xsl
= new XslFile();
      xsl.Path
= XslFile;
      xsl.DataSource
= "/sitecore/content/home";
      
string htmlOutput = xsl.RenderAsText();
      
return htmlOutput;
    }
  }
}
  1. In your non-Sitecore solution, add reference to this web service and use it in such a way:

    _3_061102.localhost.WebService1 serv = new WebService1();
    serv.Timeout = 600000;
    string txtHtml = serv.ExecuteXslt(@"D:\Inetpub\Sitecore\SITECORE_ALLSITES\5.3.0 Build 061102\xsl\sample rendering.xslt");
    Response.Write(txtHtml);