views:

255

answers:

2

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...)

+1  A: 

You can used the serialized (xml) form of your objects and edit it with the XML Editor of VS (I use VS2008).

Then associate an xsd schema to this xml document. Use the schema that xsd,exe generated itself and that it uses in the serialization/deserialization.

You will see that you get intellisense for free!

Moreover, if you edit the schema and add

    <xs:annotation>
      <xs:documentation>
        Helpful Explanation.
      </xs:documentation>
    </xs:annotation>

then the XML Editor will not only prompt you the possible elements or attributes names and values, but it will also pop-out the "Helpful Explanation" for every one of them that has the annotation data entered into the xml schema.

To learn how to associate an xml schema to an xml document either lookup the local VS2008 help or find it on MSDN online, or read it here.

Hope this helped.

Cheers,

Dimitre Novatchev

Dimitre Novatchev
A: 

This is sort of off topic but having been down the route of creating a CMS with xsl(t) and the pain that caused I'd recommend asp.net mvc for other reasons than intellisense. But that is nice.

I originally used xsl to separate out the view from the data, which it did. But the designers found it very hard going mostly because it all looked like html to them. More angle brackets etc. And I was continually having the conversation, "but why can't I have a document with everything in it"

Xsl was also slooow, and very memory hungry. Out of memory errors are embarrassing, and by the time you get them its way to late. And of course caching just uses more memory.

There really has been no looking back since we went with MVC, there is even the option of creating your own view engine if you are feeling really adventurous. So you could keep a little bit of xsl in there where you felt the need.

In fact there is already a project based on that in the MVCContrib libraries.

Hope this helps your decision

Simon Farrow