Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perform XSLT Transform as Build-Step

During a Visual Studio build, I need to have an XML file generated from another XML file. It is obvious to me an XSLT template and transform is exactly what I need.

The way I prefer to accomplish this is to use the "Custom Tool" property found on project files. Is there already a built-in tool I can use for this purpose? My next option might be to use a pre-build step of the csproj. Again, is there a (Visual Studio or MSBUILD) pre-existing or pre-installed tool that I can invoke from a pre-build step to do this?

Finally, if need be, I could have modify the .csproj file itself to add a MSbuild Task which performs the transform (I think MSBuild comes with such a Task - if not I know they are available for download).

Overall, I'd just like to know the easiest way to get this done, and how to do it. I already know how to write XSL templates. :)

like image 937
Brent Arias Avatar asked Aug 05 '11 21:08

Brent Arias


People also ask

How do you transform one XML to another XML document using XSLT transform?

The standard way to transform XML data into other formats is by Extensible Stylesheet Language Transformations (XSLT). You can use the built-in XSLTRANSFORM function to convert XML documents into HTML, plain text, or different XML schemas. XSLT uses stylesheets to convert XML into other data formats.

Is XSLT outdated?

XSLT is a mature, widely accepted standard. It can be used in browsers (even in old IE) and on the server side (nginx has an XSLT module, which can be used from programming languages, of course).


2 Answers

If you're using VS2010 you can use the built-in XslTransformation task of MSBuild 4 in a post build step.

<Target Name="AfterBuild">
  <XslTransformation
    XslInputPath="transform.xslt"
    XmlInputPaths="in.xml"
    OutputPaths="out.xml" />
</Target>
like image 73
Thomas Gerstendörfer Avatar answered Oct 04 '22 00:10

Thomas Gerstendörfer


I'd personally go with installing the MSBuild Community Tasks and invoking msbuild.exe from the PostBuild Event in the project settings.

A shudder just went down my spine at the thought of XSLT files too! :P

like image 22
Paul Carroll Avatar answered Oct 04 '22 00:10

Paul Carroll