如何将打包(导出)的样式表与 saxon 9.7+ s9api 一起使用?

How can I use a packaged (exported) stylesheet with saxon 9.7+ s9api?

从 Saxon 9.7 开始,我们必须使用不同的 s9api 过程来 "import" 打包样式表。 , Michael says "Stylesheet packages can ... be imported ... using ... the s9api API." He then referred to these 详情。

当我阅读它时,希望它很简单,我锁定了这个:

A stylesheet export file ... is accepted by any Saxon interface that accepts a source stylesheet.

所以,我创建了这个 MCV 示例:

import java.io.*;
import net.sf.saxon.Configuration;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
public class test {
    public static void main (String args[]) throws Exception {
        Processor saxProc = new Processor(false);
        Configuration saxCfg = saxProc.getUnderlyingConfiguration();
        XsltCompiler saxComp = saxProc.newXsltCompiler();
        File xslmain = new File(args[0]);
        Source xsl = new StreamSource(xslmain);
        XsltExecutable saxExe = saxComp.compile(xsl);
    }
}

像这样执行(对ee、pe和he使用9.9.1.7J)没有抛出异常:

$ javac -classpath saxon9pe.jar test.java
$ java -classpath .:saxon9he.jar test something.xsl

但是如果我打包something.xsl(即使用EE将其导出到xml文件)并像这样执行MCV,则会抛出异常:

$ java -classpath .:saxon9he.jar test something-exported.xml
Error
  SXPK0002: Cannot load expression with tag indexedFilter2. The stylesheet uses Saxon-EE features
Exception in thread "main" net.sf.saxon.s9api.SaxonApiException: Cannot load expression with tag indexedFilter2. The stylesheet uses Saxon-EE features

难道我不能使用 EE 打包一个 xsl 文件,分发 HE,并使用 HE 读取打包的样式表来执行转换吗?如果是,如何?

尝试用 -target:HE 编译它。原则上,这应该会阻止 Saxon-EE 生成 HE 运行-time 无法识别的结构。

不过我不得不说,这还没有经过彻底的测试。可能还需要使用 -opt 选项禁用选定的优化。