Monday, January 30, 2012

Is Razor or XSLT better for my project?

I've read an very good article about XSLT and RAZOR. Some people think XSLT is better when you are using Multiple templates.

I don't agree with that. For me, Xslt is good for only static html pages. (no server codes). When you need to use server code, it's a lot difficult to control with XSLT.

XSLT or Razor would help to provide a separation of concerns where the original XML or response represents your model, the XSLT or 'Razor view' represents your view. I'll leave the controller out for this example. The initial design proposal recommends XSLT, however I suggested the use of Razor instead as a more friendly view engine.

These are the reasons I suggested for Razor (C#):

  • Easier to work with and build more complicated pages.
  • Can easily produce non-*ML output, eg csv, txt, fdf
  • Less verbose templates
  • The view model is strongly typed, where XSLT would need to rely on convention, eg boolean or date values
  • Markup is more approachable, eg nbsp, newline normalization, attibute value normalization, whitespace rules
  • Built in HTML helper can generate JS validation code based on DTO attributes
  • Built in HTML helper can generate links to actions

And the arguments for XSLT over razor were:

  • XSLT is a standard and will still exist many years into the future.
  • It is hard to accidentally move logic into the view
  • Easer for non programmers (which I don't agree with).
  • It's been successful in some of our past projects.
  • Data values are HTML-encoded by default
  • Always well formed

So I'm looking for aguments on either side, recommendations or any experience making a similar choice?