xslt 到多个输出和基本输出目录
xslt to multiple output and base output directory
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 + "/";
我更正了还是漏掉了什么?
这是 URI 解析的工作方式。如果基 URI 为 /a/b/c
,相对 URI 为 w.xml
,则相对 URI 与基 URI 解析的结果为 /a/b/w.xml
。解析相对 URI 的算法是对两个字符串的语法操作,它从不尝试计算基本 URI /a/b/c
是指一个目录,一个普通文件,还是什么都没有。