Xslt task not working as expected
I have an XSLT transform that I developed in VS. It works great when I use VS to run it (via XML->Show Xslt Output). However, when I execute it via the MsBuildCommunityTasks Xslt task I get wildly different results.
Specifically, the output is only the contents of a handful of elements I don't even reference in my XSLT. I guess the default transform is picking them up开发者_如何学C.
My task declaration couldn't get any simpler:
<Xslt
Inputs="BuildLogs\partcover-results.xml"
Xsl="ExtTools\xslt\partcover.assembly.report.xsl"
RootTag=""
RootAttributes=""
Output="partcover.assembly.report.html"
/>
Perhaps msbuildtasks is using a different XSLT engine than VS uses internally? Any guidance would be appreciated.
I had trouble getting <Xslt />
to work as well. As of .NET 4.0, there is built in XmlTransformation task. Here is how it would look for your example:
<XslTransformation
OutputPaths="partcover.assembly.report.html"
XmlInputPaths="BuildLogs\partcover-results.xml"
XslInputPath="ExtTools\xslt\partcover.assembly.report.xsl"
/>
Worked for me the first time! Credit to Bryan Cook at the urban canuk, eh for providing a nice overview of the XSLT options in MSBuild
I also spent some time on trying to get this Xslt-task working, fiddling with the RootTag and Attributes. After some 2 hours i gave up and instead wrote my own task to get this done, which worked on my first try..
public override bool Execute()
{
bool result = true;
Log.LogMessage("Transforming from {0} to {1} using {2}",
XmlFile, OutputFile, XsltFile);
XmlWriter xmlWriter = null;
try
{
XslCompiledTransform xslTransform = GetXslTransform(XsltFile);
XmlReader xmlReader = GetXmlReader(XmlFile);
xmlWriter = GetXmlWriter(OutputFile);
xslTransform.Transform(xmlReader, xmlWriter);
}
catch (Exception e)
{
Log.LogErrorFromException(e);
result = false;
}
finally
{
if (xmlWriter != null)
{
xmlWriter.Flush();
xmlWriter.Close();
}
}
return result;
}
The RootTag is applied before the transformation is run, not after. Take the RootTag into consideration when writing your xslt, and it will work
精彩评论