Code Snippet
public
class VE_SQL_GeoRSS_Xslt : IHttpHandler {
public void ProcessRequest (HttpContext context
{
context.Response.ContentType =
"text/xml";
SqlDataAccessLayer dal = new SqlDataAccessLayer();
dal.GetGeoRssData(context.Request.QueryString[
"serviceToCall"]);
}
public bool IsReusable {
get {
return false;
}
}
}
(other code omitted...I am passing storedProc as a variable for the procedure to be called)
using (SqlConnection oConn = new SqlConnection(YourConnectionString))
{
using (SqlCommand oCmd = new SqlCommand())
{
oCmd.Connection = oConn;
oCmd.CommandType = CommandType.StoredProcedure;
oCmd.CommandText = storedProc;
oConn.Open();
using (XmlReader xr = oCmd.ExecuteXmlReader())
{
XPathDocument xpd = new XPathDocument(xr);
context.Cache.Insert(storedProc, xpd, null, DateTime.Now.AddMinutes(120), System.Web.Caching.Cache.NoSlidingExpiration);
TransformSqlXmlResults(ref xpd, storedProc);
}
}
}
public void TransformSqlXmlResults(ref XPathDocument outputXPathDoc, string procedureCalled)
{
XslCompiledTransform xslt = new XslCompiledTransform();
switch (procedureCalled)
{
case "stored_proc1":
xslt.Load(context.Server.MapPath(
"../XslStyleSheets/StyleSheet1.xsl"));
break;
default:
break;
}
xslt.Transform(outputXPathDoc,
null, context.Response.Output);
}