【问题标题】:xslt to multiple output and base output directoryxslt 到多个输出和基本输出目录
【发布时间】:2019-02-26 18:08:18
【问题描述】:

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>

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

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

var baseOutUri = new System.Uri(Directory.GetCurrentDirectory());
exe.BaseOutputURI = baseOutUri.AbsoluteUri;
Console.WriteLine(exe.BaseOutputURI);

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

Console.WriteLine 写道:

file:///D:/dev/fromSvn/cclb/bas/bin/debug

但输出生成于:

D:\dev\fromSvn\cclb\bas\bin

如果我想解决这个问题,我必须将我的代码修改为:

exe.BaseOutputURI = baseOutUri.AbsoluteUri + "/";

我是正确的还是我遗漏了什么?

【问题讨论】:

    标签: c# xml xslt saxon


    【解决方案1】:

    这是 URI 解析的工作方式。如果基 URI 是 /a/b/c,而相对 URI 是 w.xml,则根据基 URI 解析相对 URI 的结果是 /a/b/w.xml。解析相对 URI 的算法是对两个字符串的句法运算,它从不尝试确定基本 URI /a/b/c 是指目录、普通文件还是没有特定内容。

    【讨论】:

      猜你喜欢
      • 2019-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-22
      • 2016-03-07
      • 2010-11-10
      • 1970-01-01
      • 2021-07-19
      相关资源
      最近更新 更多