简体   繁体   English

Saxon XSLT和NodeList作为参数

[英]Saxon XSLT and NodeList as parameter

What I am trying to achieve is (using Saxon-B 9.1): 我想要实现的是(使用Saxon-B 9.1):

1) Run XSLT transformation with object of below Example class as parameter 1)使用以下Example类的对象作为参数运行XSLT转换

2) Object's properties are populated using reflexive extension function with selected Nodes 2)使用自反扩展功能为选定的节点填充对象的属性

3) Run second XSLT transformation (on different XML input) and pass the above object with populated values as parameter 3)运行第二个XSLT转换(在不同的XML输入上),并使用填充值作为参数传递上述对象

4) Insert XML nodes from the object into output document 4)将XML节点从对象插入输出文档

My class is below: 我的课程如下:

public class Example {
.   private NodeSet test;

.   public RequestInfo() {}

.   public void settest(NodeList t) {
.       this.test = t;
.   }
.   public NodeList gettest() {
.       return test;
.   }
}

First transformation seems to populate my object fine (using settest() method within XSLT) - I can see correct nodes added to the NodeList. 第一个转换似乎很好地填充了我的对象(使用XSLT中的settest()方法)-我可以看到已将正确的节点添加到NodeList中。

However, I am getting below error when running 2nd transformation and calling gettest() method from within XSLT: 但是,当运行第二次转换并从XSLT内调用gettest()方法时,出现以下错误:

NodeInfo returned by extension function was created with an incompatible Configuration

I was thinking should I not use NodeList but maybe some different, equivalent type that would be recognised by Saxon? 我在想我是否不应该使用NodeList,而应该使用Saxon可以识别的一些不同的等效类型? I tried it with NodeSet but got same error message. 我用NodeSet尝试过,但是得到了相同的错误消息。

Any help on this would be appreciated. 任何帮助,将不胜感激。

You haven't shown enough information to see exactly what you are doing wrong, but I can try and explain the error message. 您没有显示足够的信息来确切地了解您在做什么,但是我可以尝试解释错误消息。 Saxon achieves its fast performance in part by allocating integer codes to all the names used in your XML documents and stylesheets, and using integer comparisons to compare names. Saxon可以通过将整数代码分配给XML文档和样式表中使用的所有名称,以及使用整数比较来比较名称来部分实现其快速性能。 The place where the mapping of integers to names is held is the NamePool, and the NamePool is owned by the Saxon Configuration object; 存放整数到名称的映射的地方是NamePool,而NamePool则由Saxon Configuration对象拥有。 so all documents, stylesheets, etc participating in a transformation must be created under the same Configuration (it's a bit like the DOM rule that all Nodes must be created under the Document they are attached to). 因此,所有参与转换的文档,样式表等都必须在相同的配置下创建(有点像DOM规则,所有节点必须在其所附加的文档下创建)。 The message means that you've got at least two different Configuration objects around. 该消息表示您周围至少有两个不同的Configuration对象。 A Configuration gets created either explicitly by your application, or implicitly when you create a TransformerFactory, an XPathFactory, or other such objects. 配置可以由应用程序显式创建,也可以在创建TransformerFactory,XPathFactory或其他此类对象时隐式创建。

I wonder whether this mixing of XSLT and Java code is really a good idea? 我想知道XSLT和Java代码的混合是否真的是一个好主意? Often when I see it, the Java code is being used because people haven't mastered how to achieve the desired effect in XSLT. 通常,当我看到它时,便会使用Java代码,因为人们还没有掌握如何在XSLT中实现所需的效果。 There are many good reasons for NOT using the DOM with Saxon: it's very slow, it requires more lines of code, it's not thread-safe, it's harder to debug, ... 不将DOM与Saxon一起使用有很多充分的理由:它非常慢,需要更多的代码行,它不是线程安全的,调试起来更困难,...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM