如何将 XML 文档作为参数传递给 java (oracle xdk) 中的 XSL 转换?
我正在尝试将 XML 文档作为参数传递给 XSLT 样式表。我相信代码正在使用 oracle XDK 进行转换(它使用 JDK 1.4.2 和 Spring,而且我是代码库的新手,所以我不确定最终加载的是什么)。在我的第一次尝试中,我只是创建了一个文档对象并将其设置为变压器上的参数,但尝试将变量复制到树中却没有结果。我想到的问题是:
这在 XSLT 转换器的一般情况下是否可能? (看起来应该如此,因为通常 XSLT 变量/参数可以包含节点集)
是否可以专门使用 oracle XDK(或 xalan,它也在类路径中)?
如果是这样,我该如何让它发挥作用?
I'm trying to pass an XML document to an XSLT stylesheet as a parameter. I believe the code is using the oracle XDK for transformations (it's using JDK 1.4.2, and Spring, and I'm new to the codebase, so I'm not sure what is getting loaded in the end). In my first attempt, I just created a document object and set this as the parameter on the transformer, but attempts to copy the variable into the tree give no result. Questions that come to mind are:
is this even possible in the general case of XSLT transformers? (it seems like it should be, as generally XSLT variables/parameters can contain nodesets)
is it possible specifically with the oracle XDK (or xalan, which is also in the classpath)?
If so, how do I make it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是这是可能的,但是,它是不直观的,至少对于 Oracle XSL 处理器来说是这样。我尝试了以下(无效)调用(名称已更改以保护无辜者):
以及
(第二个是基于 DOMSource 可能会工作,因为它是 DOM 的 java.xml.transform 接口)。最终对我有用的调用是了解 XSL 使用 XPath,变量的有效类型本质上是字符串或节点集,并且 XPath 返回节点集。以下内容对我有用:
它基本上使用 XPath 来获取仅包含传入 DOM 对象的根文档的节点集。然而,这看起来有点像黑客,并且可能不适用于其他 XSL 处理器,所以 YMMV...
The answer is that this is possible, however, it is non-intuitive, at least for the Oracle XSL processor. I tried the following (non-working) invocations (names changed to protect the innocent):
and
(this second on the basis that maybe DOMSource would work because it was the java.xml.transform interface to the DOM). The invocation that worked for me in the end was to take the insight that XSL uses XPath, and the valid types for the variable are essentially strings or nodesets, and XPath returns nodesets. The following works for me:
Which basically uses XPath to get a nodeset containing only the root document of the passed in DOM object. However, this seems like a bit of a hack, and may not work with other XSL processors, so YMMV...