【问题标题】:xslt to multiple outputxslt 到多个输出
【发布时间】:2019-07-15 16:50:23
【问题描述】:

xsl代码如下

<xsl:template match="/">
  <xsl:for-each select="/t:Flow/t:AccountingRecords/t:AccountingRecord">
    <xsl:result-document method="xml" href="UBL-invoice.2.1-{t:Reference}-output.xml">
      <xsl:apply-templates select="."/>
    </xsl:result-document>
  </xsl:for-each>
</xsl:template>

使用transform从命令行运行良好

现在我尝试从 .net 应用程序中使用它,但出现以下错误:

$exception {"主体输出文件的系统标识符未知"} Saxon.Api.DynamicError

如果我将代码更改为

<xsl:result-document method="xml" href="file:///d:/temp/UBL-invoice.2.1-{t:Reference}-output.xml">
  <xsl:apply-templates select="."/>
</xsl:result-document>

然后我得到我的文件。

我的问题是:有没有办法使用应用程序的相对路径,或者我必须在我的 xsl 中添加一个 dir 参数?

我的代码与示例中的代码完全一致

Processor proc = new Processor();
var comp = proc.NewXsltCompiler();
Xslt30Transformer exe = comp.Compile(new Uri("file:///" + System.IO.Path.GetFullPath("./Styles/style.xslt"))).Load30();

 DocumentBuilder builder = proc.NewDocumentBuilder();
 builder.BaseUri = new Uri("file:///" + System.IO.Path.GetFullPath("./ar2.xml"));

 XdmNode inp = builder.Build(System.IO.File.OpenRead(System.IO.Path.GetFullPath("./ar2.xml")));

 Serializer serializer = proc.NewSerializer();
 serializer.SetOutputWriter(Console.Out);

 // Transform the source XML and serialize the result document
 exe.ApplyTemplates(inp, serializer); // < ==== Exception here

【问题讨论】:

    标签: c# xml xslt saxon


    【解决方案1】:

    Xslt30Transformer 对象上设置BaseOutputURI 属性。这将用作解析出现在 xsl:result-document/@href 中的相对 URI 的基本 URI。

    【讨论】:

    • 它与exe.BaseOutputURI = "file:///" + Directory.GetCurrentDirectory().Replace("\\", "/");一起工作,前缀和替换是必要的。
    • 要从 .NET 上的文件名获取 URI,请参阅 stackoverflow.com/questions/1546419/…
    猜你喜欢
    • 1970-01-01
    • 2016-03-07
    • 2010-11-10
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-06
    相关资源
    最近更新 更多