Visual Studio XGen - .xtr.xml

The central file for Visual Studio XGen is the xtransform file (extension .xtr.xml). It describes how the input XML file should be translated, by specifying an XSLT file and optionally one or more parameters.

When a transformation pass is started XGen will search your solution for files with extension .xtr.xml. And it will process those files according to a few simple rules.

Take a quick look at the file below. It is rather simple and you may be able to figure out exactly how it works just by looking at it.

<?xml version="1.0" encoding="utf-8" ?>
<xtransformations xmlns="http://vsxgen.sourceforge.net/XTransformV1.xsd">
  <xtransform xsource="input.xml" xtemplate="[xgenlib]\template.xslt" output="output.cs">
    <param name="type" value="DAL"/>
  </xtransform>
  <xtransform xsource="input.xml" xtemplate="template.xslt" output="output.sql">
    <param name="type" value="SP"/>
  </xtransform>
</xtransformations>
Did you figure it out? If not, lets dissect it piece by piece.
<?xml version="1.0" encoding="utf-8" ?>
Nothing strange here. All XML files start like that.
<xtransformations xmlns="http://vsxgen.sourceforge.net/XTransformV1.xsd">
This is the root element. All XML documents have a root element, and for an xtransform file this is the name of the root element. xmlns means xml name space and the name space for an xtransform file is http://vsxgen.sourceforge.net/XTransformV1.xsd.
  <xtransform xsource="input.xml" xtemplate="[xgenlib]\template.xslt" output="output.cs">
The xtransform element is the most important element in this file. It specifies the input file (the .xml file). Secondly, it specifies the template file (the .xslt file). Finally, you specify the name of the output file. Please note the use of [xgenlib]. This is a project variable. You can use the name of any project that you have in your solution and enclose it in angle brackets. That will then be replaced with the working directory of that project. This makes it possible to refer to files in other projects than the project that the xtransform file is in, without having to use relative or absolute paths. Project variables can be used in the xsource, xtemplate and output attributes of the xtransform element. It can also be used in the value tag in the param element.
    <param name="type" value="DAL"/>
If you want you can specify a parameter for the translation. You do that with the param tag and with the name and value attributes. You can have any number of parameter tags.
  </xtransform>
And here we are closing the xtransform tag.
  <xtransform xsource="input.xml" xtemplate="template.xslt" output="output.sql">
    <param name="type" value="SP"/>
  </xtransform>
Here's another xtransform element. It has a different output file and the parameter is different. You can use this parameter in the .xslt file.
</xtransformations>
And finally we are closing the top level tag.

And that's it.