Created
April 10, 2014 14:10
-
-
Save dshookowsky/10386405 to your computer and use it in GitHub Desktop.
Controllers/StyleController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using System.Web.Mvc; | |
using System.Xml; | |
using System.Xml.XPath; | |
using System.Xml.Xsl; | |
namespace Branding.Controllers | |
{ | |
public class StyleController : Controller | |
{ | |
private const string BRAND_XML = "brand.xml"; | |
// | |
// GET: /Style/ | |
public FileResult Index() | |
{ | |
Models.Customization c = new Models.Customization(ControllerContext.HttpContext.Request.Url.Host); | |
// Create the XslCompiledTransform and load the style sheet. | |
XslCompiledTransform xslt = new XslCompiledTransform(false); | |
xslt.Load(ControllerContext.HttpContext.Server.MapPath("~/Content/xslt/brand.xslt")); | |
// Create the XsltArgumentList. | |
XsltArgumentList argList = new XsltArgumentList(); | |
argList.AddParam("title-color", "", c.titleColor); | |
argList.AddParam("title-text-color", "", c.titleTextColor); | |
// Create an XmlWriter to write the output. | |
MemoryStream stream = new MemoryStream(); | |
XmlWriterSettings settings = new XmlWriterSettings(); | |
settings.OmitXmlDeclaration = true; | |
settings.ConformanceLevel = ConformanceLevel.Fragment; | |
XmlWriter writer = XmlWriter.Create(stream, settings); | |
// Transform the file. | |
xslt.Transform(new XPathDocument(ControllerContext.HttpContext.Server.MapPath("~/Content/xml/brand.xml")), argList, writer); | |
writer.Close(); | |
stream.Position = 0; | |
return new FileStreamResult(stream, "text/css"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment