Xslt 任务未按预期工作

发布于 2024-08-10 01:48:35 字数 490 浏览 9 评论 0原文

我有一个在 VS 中开发的 XSLT 转换。当我使用 VS 运行它时(通过 XML->Show Xslt Output)它效果很好。然而,当我通过 MsBuildCommunityTasks Xslt 任务执行它时,我得到了截然不同的结果。

具体来说,输出只是一些我什至没有在 XSLT 中引用的元素的内容。我猜默认的变换是拾取它们。

我的任务声明再简单不过了:

<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" 
/>

也许 msbuildtasks 使用的 XSLT 引擎与 VS 内部使用的不同?任何指导将不胜感激。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

泪是无色的血 2024-08-17 01:48:35

我也无法让 正常工作。从 .NET 4.0 开始,内置了 XmlTransformation 任务。以下是您的示例的外观:

  <XslTransformation 
   OutputPaths="partcov​er.assembly.report.h​tml" 
   XmlInputPaths="BuildLo​gs\partcover-result​s.xml"
   XslInputPath="ExtTools\​xslt\partcover.asse​mbly.report.xsl"
  />

第一次为我工作!感谢 城市 Canuk 的 Bryan Cook,嗯提供了 MSBuild 中 XSLT 选项的良好概述

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

冷清清 2024-08-17 01:48:35

我还花了一些时间尝试让这个 Xslt 任务正常工作,摆弄 RootTag 和属性。大约两个小时后,我放弃了,而是编写了自己的任务来完成这项工作,这在我的第一次尝试中发挥了作用。

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

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;
}
时间海 2024-08-17 01:48:35

RootTag 在转换运行之前应用,而不是之后。编写 xslt 时考虑 RootTag,它会起作用

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文