Saxon .Net 改造

Saxon .Net transformation

也许这是个愚蠢的问题,但我是 XSL 的新手。

我正在使用这个命令行执行一个非常有效的转换:

transform.exe -s: source.xml -xsl:rules.xsl -o: output.xml -xi:on

我正在尝试通过 C# 实现相同的结果,但输出文件为空。 “-xi”参数的等效项是什么?

谢谢。

  Uri xslUri = new Uri(@"rules.xsl");
  Uri inputUri = new Uri(@"source.xml");
  Uri outputUri = new Uri(@"toc.hhc");

  // Compile stylesheet
  try
  {
    Processor processor = new Processor();
    XdmNode input = processor.NewDocumentBuilder().Build(inputUri);
    XsltCompiler compiler = processor.NewXsltCompiler();
    XsltExecutable exec = compiler.Compile(xslUri);
    XsltTransformer transformer = exec.Load();
    transformer.InitialContextNode = input;

    // Create a serializer
    Serializer serializer = new Serializer();
    FileStream fs = new FileStream(outputUri.AbsolutePath, FileMode.Create, FileAccess.Write);
    serializer.SetOutputStream( fs );

    // Transform the source XML to System.out.
    transformer.Run( serializer );
  }
  catch( Exception e )
  {
    Console.WriteLine( e.Message );
  }

我需要对其进行测试才能 100% 确定它是否有效,但我认为您应该能够做到

processor.setProperty("http://saxon.sf.net/feature/xinclude-aware", "true")

我尝试设置 proc.Implementation.setXIncludeAware(true);,但它不适用于 Saxon 9.6.0.7。因此,我将我的结果发布在 https://saxonica.plan.io/boards/3/topics/6206 and Saxonica created the bug report https://saxonica.plan.io/issues/2488 上,后来修复了。因此,您似乎必须等到修复程序包含在新版本中才能在 .NET 应用程序中使用 XInclude。