解决了Saxon 9 HE,Java中的问题-静态错误,XTSE0210,XTSE0165,XPST0017后看到的错误
从以下Java代码调用XSLT转换时
public static Document transformAsDocument(Document inputDoc, String xslDoc, Map<String,
Object> params, String xslContextPath, String fullXsltFilePath) throws XmlException {
try {
System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
TransformerFactory factory = TransformerFactory.newInstance();
factory.setURIResolver(new ClasspathResourceURIResolver(xslContextPath));
factory.setAttribute(FeatureKeys.GENERATE_BYTE_CODE, false);
String systemId = XMLUtils.class.getResource(fullXsltFilePath).toString();
Templates template = factory.newTemplates(new StreamSource(new StringReader(xslDoc), systemId));
Transformer xformer = template.newTransformer();
if (params != null) {
for (Map.Entry<String, Object> entry : params.entrySet()) {
xformer.setParameter(entry.getKey(), entry.getValue());
}
}
DOMResult result = new DOMResult();
DOMSource domSource = new DOMSource(inputDoc);
xformer.transform(domSource, result);
return (Document) result.getNode();
} catch (TransformerConfigurationException e) {
throw new XmlException(e);
} catch (TransformerException e) {
SourceLocator locator = e.getLocator();
if (locator != null) {
Map<String, Object> message = new HashMap<String, Object>();
message.put("col", locator.getColumnNumber());
message.put("line", locator.getLineNumber());
message.put("publicId", locator.getPublicId());
message.put("systemId", locator.getSystemId());
throw new XmlException(message.toString(), e);
}
throw new XmlException(e);
} catch (Exception e) {
throw new XmlException(e);
}
}
我们看到以下堆栈跟踪。
java.lang.NullPointerException
at net.sf.saxon.lib.StandardURIResolver.resolve(StandardURIResolver.java:153)
at net.sf.saxon.functions.DocumentFn.resolveURI(DocumentFn.java:411)
at net.sf.saxon.functions.DocumentFn.makeDoc(DocumentFn.java:283)
at net.sf.saxon.functions.DocAvailable.docAvailable(DocAvailable.java:68)
at net.sf.saxon.functions.DocAvailable.isDocAvailable(DocAvailable.java:31)
at net.sf.saxon.functions.DocAvailable.call(DocAvailable.java:45)
at net.sf.saxon.functions.DocAvailable.call(DocAvailable.java:21)
at net.sf.saxon.expr.FunctionCall.iterate(FunctionCall.java:547)
at net.sf.saxon.expr.Expression.effectiveBooleanValue(Expression.java:886)
at net.sf.saxon.expr.instruct.Choose.choose(Choose.java:901)
at net.sf.saxon.expr.instruct.Choose.iterate(Choose.java:952)
at net.sf.saxon.expr.instruct.GlobalVariable.getSelectValue(GlobalVariable.java:643)
at net.sf.saxon.expr.instruct.GlobalVariable.actuallyEvaluate(GlobalVariable.java:724)
at net.sf.saxon.expr.instruct.GlobalVariable.evaluateVariable(GlobalVariable.java:692)
at net.sf.saxon.expr.GlobalVariableReference.evaluateVariable(GlobalVariableReference.java:126)
at net.sf.saxon.expr.VariableReference.evaluateItem(VariableReference.java:559)
at net.sf.saxon.expr.SimpleStepExpression.iterate(SimpleStepExpression.java:113)
at net.sf.saxon.expr.SlashExpression.iterate(SlashExpression.java:902)
at net.sf.saxon.expr.Atomizer.iterate(Atomizer.java:321)
at net.sf.saxon.expr.GeneralComparison.effectiveBooleanValue(GeneralComparison.java:685)
at net.sf.saxon.expr.instruct.Choose.choose(Choose.java:901)
at net.sf.saxon.expr.instruct.Choose.iterate(Choose.java:952)
at net.sf.saxon.expr.instruct.GlobalVariable.getSelectValue(GlobalVariable.java:643)
at net.sf.saxon.expr.instruct.GlobalVariable.actuallyEvaluate(GlobalVariable.java:724)
at net.sf.saxon.expr.instruct.GlobalVariable.evaluateVariable(GlobalVariable.java:692)
at net.sf.saxon.expr.GlobalVariableReference.evaluateVariable(GlobalVariableReference.java:126)
at net.sf.saxon.expr.VariableReference.iterate(VariableReference.java:536)
at net.sf.saxon.expr.instruct.ForEach.processLeavingTail(ForEach.java:434)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:687)
at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:347)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:505)
at net.sf.saxon.Controller.transformDocument(Controller.java:2423)
at net.sf.saxon.Controller.transform(Controller.java:1979)
at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:596)
at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:73)
java.lang.AssertionError: Internal error: no value for variable $g_ndsTemplateDoc at line 118 of
at net.sf.saxon.expr.VariableReference.iterate(VariableReference.java:547) ~[Saxon-HE-9.8.0-15.jar:na]
at net.sf.saxon.expr.instruct.ForEach.processLeavingTail(ForEach.java:434) ~[Saxon-HE-9.8.0-15.jar:na]
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:687) ~[Saxon-HE-9.8.0-15.jar:na]
at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:347) ~[Saxon-HE-9.8.0-15.jar:na]
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:505) ~[Saxon-HE-9.8.0-15.jar:na]
at net.sf.saxon.Controller.transformDocument(Controller.java:2423) ~[Saxon-HE-9.8.0-15.jar:na]
at net.sf.saxon.Controller.transform(Controller.java:1979) ~[Saxon-HE-9.8.0-15.jar:na]
at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:596) ~[Saxon-HE-9.8.0-15.jar:na]
at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:73) ~[Saxon-HE-9.8.0-15.jar:na]
该错误来自以下XSLT代码段,该代码段位于大型XSLT的链中。
<xsl:variable name="paramsDoc" select="if (doc-available('input:request')) then doc('input:request') else ()"/>
相同的XSLT可从命令行运行,如Saxon 9 HE,Java-静态错误,XTSE0210,XTSE0165,XPST0017
问题来源:Stack Overflow
ClasspathResourceURIResolver当要求您解析URI时,返回的内容是什么input:request?似乎已经返回了一个source将Saxon带入代码路径的对象
if (source instanceof StreamSource &&
((StreamSource)source).getInputStream() == null &&
((StreamSource)source).getReader() == null) {
然后,Saxon尝试使用标准URI解析器来解析此Source对象中的URI:
String uri = source.getSystemId();
resolver = context.getController().getStandardURIResolver();
try {
source = resolver.resolve(uri, "");
这崩溃了,因为它uri为null。
Saxon的假设,当一个StreamSource被返回的用户提供的URIResolver,那么StreamSource将包含一个或者InputStream或者Reader或者SystemID,但似乎它包含没有这些。撒克逊人应该报告这很好而不是崩溃,但是它不能对这样的Source对象做任何有用的事情。
回答来源:Stack Overflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。