Java 将XSLT转换移动到其他项目后没有返回值
我有以下代码将xml文档转换为html页面。这没什么特别的,只是我使用saxon工厂进行转换,因为我需要XSLT2.0中的函数Java 将XSLT转换移动到其他项目后没有返回值,java,xml,xslt,transformation,Java,Xml,Xslt,Transformation,我有以下代码将xml文档转换为html页面。这没什么特别的,只是我使用saxon工厂进行转换,因为我需要XSLT2.0中的函数 try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); StreamResult output = new StreamResult(bos); StreamSource input = new StreamSource(new FileReader(Transformatio
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
StreamResult output = new StreamResult(bos);
StreamSource input = new StreamSource(new FileReader(TransformationTest.class.getResource(sourceFileName).getFile()));
StreamSource stylesheet = new StreamSource(TransformationTest.class.getResourceAsStream(STYLESHEET));
Transformer tr = TransformerFactory.newInstance("net.sf.saxon.TransformerFactoryImpl", null).newTransformer(stylesheet);
tr.transform(input, output);
return bos.toString();
} catch (TransformerException e) {
throw new RuntimeException("XSL-Transform: Error while transforming the document.");
} catch (FileNotFoundException e) {
throw new RuntimeException("XSL-Transform: Error while reading the source file.");
}
该代码在一个单独的项目中运行良好,添加了saxon作为依赖项。我尝试了不同的输入,每次都得到了正确的输出
现在我尝试将它添加到一个更大的项目中,该项目在类路径中有许多其他库,但代码突然停止工作。输出为空,没有异常,没有错误消息,只返回一个空字符串。我不是变压器方面的专家,所以我需要一些帮助。这种行为的确切原因是什么?我如何修复它?我们从命令行使用Saxon 9运行代码开始,然后检查它是否也只输出空字符串。如果是这种情况,那么我们需要查看XSLT和输入。在许多情况下,名称空间存在问题,例如XSLT没有
..
,而XML输入有..
。