Menu

Quick Guide

Munir Husseini

How to start

Download the assembly MunirHusseini.T4Xslt.dll or
download and compile the Visual Studio solution. The project T4Xslt productes the assembly MunirHusseini.T4Xslt.dll that contains the base class for T4 templates to support XSLT transformations, MunirHusseini.T4Xslt.

How to reference the class T4Xslt

For the XSLT transformation to work, your T4 template needs to inherit from MunirHusseini.T4Xslt. So basically, you have two options:

1. Install the assmbly MunirHusseini.T4Xslt.dll into the GAC using

    gacutil -i MunirHusseini.T4Xslt.dll

and reference the assembly in the T4 template with

    <#@ assembly name="MunirHusseini.T4Xslt.dll" #>

2. Place the assmbly MunirHusseini.T4Xslt.dll anywhere you like and reference the assembly in the T4 template e.g. with

    <#@ assembly name="$(SolutionDir)\Dependencies\MunirHusseini.T4Xslt.dll" #>

How to specify the input XML file

Place the string input: mydata.xml (mydata.xml is just an example file name - replace with your own) anywhere within the T4 template. Remember to keep the XSLT markup valid. This means, you can either place the string inside the XSLT markup as a comment or before the XSLT markup without a comment.

Note that you can specifiy Visual Studio macros in the input file path. Visual studio macros are the text placeholders you can also use in the build events or in MSBuild files. Examples of such macros are $(SolutionDir), $(ProjectDir) or $(ConfigurationName).

How to specify the XSLT markup

Just type (or paste) it into the T4 file. No special tags are required.

Examples

<#@ template hostspecific="true" inherits="MunirHusseini.T4Xslt" language="C#" #>
<#@ output extension="html" #>
<#@ assembly name="MunirHusseini.T4Xslt.dll" #>
<?xml version="1.0" encoding="UTF-8"?>
<!-- input: $(ProjectDir)\todo-list.xml -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <!-- ... -->
</xsl:template>
</xsl:stylesheet>

<#@ template hostspecific="true" inherits="MunirHusseini.T4Xslt" language="C#" #>
<#@ output extension="html" #>
<#@ assembly name="$(SolutionDir)\Dependencies\MunirHusseini.T4Xslt.dll" #>
input: $(ProjectDir)\todo-list.xml

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <!-- ... -->
    </xsl:template>
</xsl:stylesheet>