Josh Buedel
Josh Buedel

Reputation: 1863

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.

My task declaration couldn't get any simpler:

<Xslt 
  Inputs="BuildLo​gs\partcover-result​s.xml" 
  Xsl="ExtTools\​xslt\partcover.asse​mbly.report.xsl​" 
  RootTag="" 
  RootAttributes="" 
  Output="partcov​er.assembly.report.h​tml" 
/>

Perhaps msbuildtasks is using a different XSLT engine than VS uses internally? Any guidance would be appreciated.

Upvotes: 1

Views: 2687

Answers (3)

Marius
Marius

Reputation: 58949

The RootTag is applied before the transformation is run, not after. Take the RootTag into consideration when writing your xslt, and it will work

Upvotes: 0

Jim Counts
Jim Counts

Reputation: 12795

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="partcov​er.assembly.report.h​tml" 
   XmlInputPaths="BuildLo​gs\partcover-result​s.xml"
   XslInputPath="ExtTools\​xslt\partcover.asse​mbly.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

Upvotes: 2

Bart Janson
Bart Janson

Reputation: 233

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;
}

Upvotes: 0

Related Questions