Hey Everyone,
I'm looking at building a templating engine for my website. I'm using ASP.NET MVC and Linq-to-SQL.
So,
What I'm wanting to do is generate an XML document like this:
<?xml version="1.0" encoding="utf-8" ?>
<MainPage>
<MainPageHtml><![CDATA[<p>lol!</p><br/>wtf? totally!]]></MainPageHtml>
<Roles>
<Role RoleId="1">User</Role>
<Role RoleId="2">Administrator</Role>
</Roles>
</MainPage>
And transform it with XSLT like this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="no" encoding="iso8859-1" omit-xml-declaration="yes"/><xsl:template match="/">
<xsl:value-of select="/MainPage/MainPageHtml"/>
<![CDATA[<select>]]><xsl:for-each select="//Roles/Role">
<![CDATA[<option value="]]><xsl:value-of select="@RoleId"/><![CDATA[">]]><xsl:value-of select="."/><![CDATA[</option>]]></xsl:for-each>
<![CDATA[</select>]]></xsl:template>
</xsl:stylesheet>
Using this sort of code:
XmlDocument data = new XmlDocument(); data.Load("Data.xml");
XslCompiledTransform transform = new XslCompiledTransform(); transform.Load("Transform.xslt");
StringWriter sw = new StringWriter();
transform.Transform(data, null, sw);
Console.WriteLine(sw.ToString());
Console.ReadKey(true);
Is there a quick way to turn a Linq based Model like this:
return View("MainPage", new MainPageModel
{
MainPageHtml = Config.MainPageHtml,
Roles = Config.GetAllRoles()
});
Into the model above?