Saxon 9,Java,NullPointer from doc-available

问题描述 投票:0回答:1

这是解决Saxon 9 HE, Java - Static errors, 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 ()"/>

与在Saxon 9 HE, Java - Static errors, XTSE0210, XTSE0165, XPST0017中一样,相同的XSLT在命令行中也可以工作>

这是在解决Saxon 9 HE中的问题后出现的错误,Java-静态错误,XTSE0210,XTSE0165,XPST0017从以下Java代码公共静态文档中调用XSLT转换时...

java saxon
1个回答
0
投票

[被要求解析URI ClasspathResourceURIResolverinput:request返回什么?似乎返回了一个source对象,该对象将Saxon带入代码路径

if (source instanceof StreamSource && 
    ((StreamSource)source).getInputStream() == null &&
    ((StreamSource)source).getReader() == null) {
© www.soinside.com 2019 - 2024. All rights reserved.