views:

258

answers:

1

I am just getting into the idea of code generation for repetitive coding tasks and have seen both of these approaches. I've seen the XSLT approach in an Apress book Code Generation in Microsoft .Net and have read about the T4 approach in relation to what's new in the MVC framework.

What kind of projects is each method better suited for? A quick glance tells me that T4 is a more lightweight system, is that true?

Many thanks...

+3  A: 

Well yes - T4 is a template-based approach that can pull information from a variety of sources - typically from a database (table or system catalogs).

T4 is built into VS 2008 - you can define a .tt file inside VS2008 and have it generate its output inside VS.

XSLT has one requirement - input must be XML, and XSLT itself also is XML, so there's a number of challenges and possible drawbacks there.

XSLT is stand-alone - you can install and use any number of XSL engines.

All in all: T4 to me is more of a "inside VS" code-generation tool (to quickly create C# or other files), while XSLT is more of a data-processing/data-transformation tool to turn data from XML into another format (typically HTML or PDF using XSL-FO).

Marc

marc_s