使用java获取xsl消息 [英] using java to get xsl message

查看:49
本文介绍了使用java获取xsl消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 JAXP 在 JTextArea 中打印 .我的问题是,我无法用我的变压器创建 saxonica 控制器,我不知道为什么,因为我正在使用 TransformerFactoryImpl,因为在某些答案中被调用.

I'm trying to print the <xsl:message> in a JTextArea using JAXP. My Problem is, that I can't create a saxonica Controller with my transformer and I don't know why because I'm using TransformerFactoryImpl as in some answers is called.

这是我的 Java 代码:

Here is my Java Code:

public static void xslTransform(File xmlFile,File xslFile, JTextArea output){
StreamSource source = new StreamSource(xmlFile);
StreamResult result = new StreamResult(xslFile);
TransformerFactoryImpl tfimpl = new TransformerFactoryImpl();
Transformer transformer = tfimpl.newInstance().newTransformer(new StreamSource(xslFile));
Controller controller = new Controller(transformer);

控制器导入:

net.sf.saxon.Controller;

希望有人能帮助我.

卡夫

推荐答案

Controller 类上从来没有一个构造函数以 JAXP Transformer 作为参数,我不知道你从哪里得到这个想法.

There has never been a constructor on the Controller class that took a JAXP Transformer as a parameter, I don't know where you got that idea from.

>

在 Saxon 9.6 之前的版本中,如果要调用 Controller 对象上的方法,可以将 Transformer 转换为 Controller,即

In releases prior to Saxon 9.6, you can cast the Transformer to a Controller if you want to call methods on the Controller object, that is

Controller controller = (Controller)transformer;

在 9.6 中,Controller 和 Transformer 之间的关系发生了变化,因为 JAXP API 变得越来越不适合利用 XSLT 3.0 中可用的工具.您现在可以将 Transformer 转换为 net.sf.saxon.jaxp.TransformerImpl,并且您可以从 TransformerImpl 调用 getUnderlyingController() 以到达控制器.

In 9.6, the relationship between Controller and Transformer has changed, because the JAXP API is becoming increasingly unsuitable to take advantage of the facilities becoming available in XSLT 3.0. You can now cast the Transformer to net.sf.saxon.jaxp.TransformerImpl, and from the TransformerImpl you can call getUnderlyingController() to get to the Controller.

但是你真的想这样做吗?另一种方法是做

But do you really want to do it this way? An alternative would be to do

factory.setAttribute(FeatureKeys.MESSAGE_EMITTER_CLASS, MyMessageEmitter.class)

其中 MyMessageEmitter 是您对 Saxon 的 MessageEmitter inferface 的实现.

where MyMessageEmitter is your implementation of Saxon's MessageEmitter inferface.

这篇关于使用java获取xsl消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆