XSLT帮助在java中运行
我是 XSLT 世界的新手,我基本上是尝试从 HERE 运行 JSON 转换
但是如果我使用这种方法:
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource("src\\json\\xml-to-json.xsl"));
transformer.transform(new StreamSource("src\\json\\xmltest.xml"), new StreamResult(new FileOutputStream("birds.out")));
System.out.println(result);
我收到以下错误:
SystemId Unknown; Line #59; Column #127; Could not find function: if
SystemId Unknown; Line #59; Column #127; Extra illegal tokens: 'then', 'http://json.org/', ':', 'create-node', '(', '$', 'input', ',', 'false', '(', ')', ')', 'else', 'http://json.org/', ':', 'create-simple-node', '(', '$', 'input', ')'
SystemId Unknown; Line #59; Column #127; function token not found.
如果我使用 Saxon,由于许可,我宁愿使用 inbuit ,但只需调用它就可以工作的 main:
String[] args = new String[2];
args[0]="d:\\xmltest.xml";
args[1]="d:\\xml-to-json.xsl";
net.sf.saxon.Transform.main(args);
但我不确定如何正确编码(不调用 main)用Java编写,这样我就可以存储结果。
干杯
Im new to the XSLT world, I am basically trying to run the JSON convertion from HERE
However if I use this method:
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource("src\\json\\xml-to-json.xsl"));
transformer.transform(new StreamSource("src\\json\\xmltest.xml"), new StreamResult(new FileOutputStream("birds.out")));
System.out.println(result);
I get the following error:
SystemId Unknown; Line #59; Column #127; Could not find function: if
SystemId Unknown; Line #59; Column #127; Extra illegal tokens: 'then', 'http://json.org/', ':', 'create-node', '(', '
If I use Saxon, I would rather use the inbuit one due to licensing, but just call the main it works:
String[] args = new String[2];
args[0]="d:\\xmltest.xml";
args[1]="d:\\xml-to-json.xsl";
net.sf.saxon.Transform.main(args);
But im not sure how to actually code that correctly (not calling main) in Java so I can store the results.
Cheers
, 'input', ',', 'false', '(', ')', ')', 'else', 'http://json.org/', ':', 'create-simple-node', '(', '
If I use Saxon, I would rather use the inbuit one due to licensing, but just call the main it works:
But im not sure how to actually code that correctly (not calling main) in Java so I can store the results.
Cheers
, 'input', ')'
SystemId Unknown; Line #59; Column #127; function token not found.
If I use Saxon, I would rather use the inbuit one due to licensing, but just call the main it works:
But im not sure how to actually code that correctly (not calling main) in Java so I can store the results.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有两个问题。 1)为什么第一次尝试会失败并出现错误? 2)如何从 Saxon 获得结果?
1) 第一次尝试失败,因为您使用的是 XSLT 1.0 处理器。正如您引用的页面所说,
因此,如果您使用 XSLTJSON Lite,您的问题应该得到解决。
2) 如果您仍然想尝试 Saxon,此页面看起来有用的。它不是直接调用 Saxon,而是
在
There are two questions here. 1) Why is the first attempt failing with errors? and 2) how to get results from Saxon?
1) The first attempt fails because you're using an XSLT 1.0 processor. As the page you referenced says,
So if you use XSLTJSON Lite, your problems should be solved.
2) If you still want to try Saxon, this page looks useful. Rather than calling Saxon directly, it uses
before the