XSL(like) declarative language as MVC view over strongtyped model?
- by Martin Kool
As a huge XSL fan, I am very happy to use xsl as the view in our proprietary MVC framework on ASP.NET. Objects in the model are serialized under the hood using .NET's xml serializer, and we use quite atomic xsl templates to declare how each object or property should transform.
For example:
<xsl:template match="/Article">
<html>
<body>
<div class="article">
<xsl:apply-templates />
</div>
</body>
</html>
</xsl:template>
<xsl:template match="Article/Title">
<h1>
<xsl:apply-templates />
</h1>
</xsl:template>
<xsl:template match="@*|text()">
<xsl:copy />
</xsl:template>
This mechanism allows us to quickly override default matching templates, like having a template matching on the last item in a list, or the selected one, etc. Also, xsl extension objects in .NET allow us just the bit of extra grip that we need. Common shared templates can be split up and included.
However
Even though I can ignore the verbosity downside of xsl (because Visual Studio schema intellisense + snippets really is slick, praise to the VS-team), the downside of not having intellisense over strongtyped objects in the model is really something that's bugging me.
I've seen ASP.NET MVC + user controls in action and really starting to love it, but I wonder;
Is there a way of getting some sort of intellisense over XML that we're iterating over, or do you know of a language that offers the freedom and declarativeness of XSL but has the strongtype/intellisense benefits of say webforms/usercontrols/asp.net.mvc-view?
(I probably know the answer: "no", and I'll find myself using Phil Haack's utterly cool mvc shizzle soon...)