Saxon.Api.StaticError: 'xsl:import-schema require Saxon-EE' with .net API



我已经下载了。NET Saxon API。我已经编译并运行了EE示例应用程序。其中一些需要许可证,而我有一个许可证文件,这似乎使它发挥了作用。

我想在xslt中使用xsl:import-schema,这个xslt在Oxygen编辑器中工作(它有自己的EE许可证(。

如果我从saxon示例中取一个简单的xslt示例,然后尝试使用import-schema指令编译xslt:

Saxon.Api.StaticError: 'xsl:import-schema requires Saxon-EE'

这是真的。然而,我已经明确引用了Saxon EE库,所以这不应该是一个问题(请参阅下面的线索(:

这是我的代码:

var samplesDir = new Uri(AppDomain.CurrentDomain.BaseDirectory);
String dir = samplesDir.LocalPath;
String sourceFile = Path.Combine(dir,"po.xml");
String styleFile = Path.Combine(dir,"po.xsl");
// Create a Processor instance.
Processor processor = new Processor();
// Load the source document
DocumentBuilder builder = processor.NewDocumentBuilder();
builder.BaseUri = new Uri(sourceFile);
XdmNode input = builder.Build(File.OpenRead(sourceFile));
XsltCompiler compiler = processor.NewXsltCompiler();
//compiler.SchemaAware = true;
compiler.BaseUri = new Uri(styleFile);
// fails on next line
Xslt30Transformer transformer = compiler.Compile(File.OpenRead(styleFile)).Load30();
// Set the root node of the source document to be the global context item
transformer.GlobalContextItem = input;
// Create a serializer, with output to the standard output stream
Serializer serializer = processor.NewSerializer();
serializer.SetOutputWriter(Console.Out);
// Transform the source XML and serialize the result document
transformer.ApplyTemplates(input, serializer);

注意,如果我注释掉显式设置以将SchemaAware设置设置为true,它会显示:

net.sf.saxon.trans.LicenseException
HResult=0x80131500
Message=Requested feature (schema-aware XSLT) requires Saxon-EE. You are using Saxon-EE software, but the Configuration is an instance of net.sf.saxon.Configuration; to use this feature you need to create an instance of com.saxonica.config.EnterpriseConfiguration
Source=saxon9ee
StackTrace:
at net.sf.saxon.Configuration.checkLicensedFeature(Int32 feature, String name, Int32 localLicenseId)
at net.sf.saxon.PreparedStylesheet..ctor(Compilation compilation)
at net.sf.saxon.style.StylesheetModule.loadStylesheet(Source styleSource, Compilation compilation)
at net.sf.saxon.style.Compilation.compileSingletonPackage(Configuration config, CompilerInfo compilerInfo, Source source)
at net.sf.saxon.s9api.XsltCompiler.compile(Source source)
at Saxon.Api.XsltCompiler.Compile(Stream input)
at ValidateXslt.Program.Main(String[] args) in C:Usersm_r_nsourcereposSaxonEEExampleValidateXsltProgram.cs:line 33

这是一个更好的线索。它告诉我我正在使用saxon EE,但不知何故,我需要一个com.saxonica.config.EnterpriseConfiguration的实例。

为什么我收到此错误消息?

您需要告诉处理器要表现得像一个许可副本(看起来有点奇怪(

Processor processor = new Processor(true);

很简单,我复制了一个不需要花哨功能的例子,但我会让这个问题保持原样,以防其他人也有同样的问题。

最新更新