xslt 到多个输出

xslt to multiple output

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 {"The system identifier of the principal output file is unknown"} 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

Xslt30Transformer 对象上设置 BaseOutputURI 属性。这将用作解析 xsl:result-document/@href.

中出现的相对 URI 的基础 URI