1

I build saxon9-7-0-4source.zip and try to execute the xPath .//item[@name='entry']//property[matches(@value,'test[0-9]{1,2}$')]/.. at a dom4j document based on the following xml:

<root>
<item name="abc">
  <iitem>
    <property value="test"/>
  </iitem>
</item>
<item name="entry">
  <iitem>
    <property value="test"/>
  </iitem>
  <iitem>
    <iiitem>
      <property value="test12"/>
    </iiitem>
  </iitem>
  <iitem>
    <property value="123"/>
  </iitem>
</item>
</root>

The xPath does what I exspect, I test it online at http://www.qutoric.com/xslt/analyser/xpathtool.html

But if I try the same in my java code

        Processor proc = new Processor(false);
        proc.getUnderlyingConfiguration().registerExternalObjectModel(new DOM4JObjectModel());
        DocumentBuilder db = proc.newDocumentBuilder();
        XdmNode xdmDoc = db.wrap(doc4j);
        XPathCompiler xpath = proc.newXPathCompiler();
        String path=".//item[@name='entry']//property[matches(@value,'test[0-9]{1,2}$')]/..";
        XPathExecutable viewPath = xpath.compile(path);

I get an unexpected error Exception in thread "main"

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Cannot instantiate the type SystemFunctionCall

    at net.sf.saxon.functions.SystemFunction.makeFunctionCall(SystemFunction.java:94)
    at net.sf.saxon.functions.RegexFunction.makeFunctionCall(RegexFunction.java:69)
    at net.sf.saxon.functions.RegexFunctionSansFlags.makeFunctionCall(RegexFunctionSansFlags.java:49)
    at net.sf.saxon.functions.SystemFunctionLibrary.bind(SystemFunctionLibrary.java:91)
    at net.sf.saxon.functions.FunctionLibraryList.bind(FunctionLibraryList.java:105)
    at net.sf.saxon.expr.parser.XPathParser.parseFunctionCall(XPathParser.java:3015)
    at net.sf.saxon.expr.parser.XPathParser.parseBasicStep(XPathParser.java:2005)
    at net.sf.saxon.expr.parser.XPathParser.parseStepExpression(XPathParser.java:1890)
    at net.sf.saxon.expr.parser.XPathParser.parseRelativePath(XPathParser.java:1815)
    at net.sf.saxon.expr.parser.XPathParser.parsePathExpression(XPathParser.java:1777)
    at net.sf.saxon.expr.parser.XPathParser.parseSimpleMappingExpression(XPathParser.java:1791)
    at net.sf.saxon.expr.parser.XPathParser.parseUnaryExpression(XPathParser.java:1666)
    at net.sf.saxon.expr.parser.XPathParser.parseExprSingle(XPathParser.java:653)
    at net.sf.saxon.expr.parser.XPathParser.parseExpression(XPathParser.java:592)
    at net.sf.saxon.expr.parser.XPathParser.parsePredicate(XPathParser.java:1958)
    at net.sf.saxon.expr.parser.XPathParser.parseStepExpression(XPathParser.java:1900)
    at net.sf.saxon.expr.parser.XPathParser.parseRelativePath(XPathParser.java:1820)
    at net.sf.saxon.expr.parser.XPathParser.parsePathExpression(XPathParser.java:1777)
    at net.sf.saxon.expr.parser.XPathParser.parseSimpleMappingExpression(XPathParser.java:1791)
    at net.sf.saxon.expr.parser.XPathParser.parseUnaryExpression(XPathParser.java:1666)
    at net.sf.saxon.expr.parser.XPathParser.parseExprSingle(XPathParser.java:653)
    at net.sf.saxon.expr.parser.XPathParser.parseExpression(XPathParser.java:592)
    at net.sf.saxon.expr.parser.XPathParser.parse(XPathParser.java:464)
    at net.sf.saxon.expr.parser.ExpressionTool.make(ExpressionTool.java:98)
    at net.sf.saxon.sxpath.XPathEvaluator.createExpression(XPathEvaluator.java:144)
    at net.sf.saxon.s9api.XPathCompiler.internalCompile(XPathCompiler.java:506)
    at net.sf.saxon.s9api.XPathCompiler.compile(XPathCompiler.java:481)
    at xslt.XSLT.main(XSLT.java:35)

This error occurs if I try to compile the xPath via XPathExecutable viewPath = xpath.compile(path);.

StellaMaris
  • 877
  • 2
  • 12
  • 29
  • 2
    GIven that you seem to be building a Saxon version yourself from source code, and given the error message ("cannot instantiate..."), I suspect a build problem. Probably there is a class that net.sf.saxon.expr.SystemFunctionCall needs which you've left out of the build. Running with class loader tracing might help to diagnose it. – Michael Kay Apr 05 '16 at 14:41
  • I was running the relevant code-snippet in a standard java application and got the stack trace which you can find in my edit post. – StellaMaris Apr 06 '16 at 23:51

1 Answers1

0

I figured out the reason where this Exception comes from. My version of eclipse is to old like it is described here. I have to compile saxon 9.7 against java 8.

Community
  • 1
  • 1
StellaMaris
  • 877
  • 2
  • 12
  • 29
  • Saxon 9.7 should run with any Java version from 1.6 up, but I've never tried compiling the source under Eclipse. The most likely explanation for the symptoms described is that the expression calls matches(), which requires the regular expression engine, and the regex engine uses some XML data files which are in the "data" directory in the JAR file. Failure to include these in your build would explain the symptoms you are describing. – Michael Kay Apr 07 '16 at 13:32