XPathCompiler.compile()在“order by”上抛出异常

时间:2017-11-07 20:25:55

标签: java saxon

对于以下代码,它会抛出异常。由于order by

Configuration config = createEnterpriseConfiguration();
Processor processor = new Processor(config);
XPathCompiler xpath = processor.newXPathCompiler();
XPathExecutable exe = xPath.compile("for $x in /Order_1/Order_2 order by $x/@id descending, $X/@name ascending return $x");

它适用于:

XPathExecutable exe = xPath.compile("for $x in /Order_1/Order_2 return $x");

XPathException是:

Message: net.sf.saxon.trans.XPathException: expected "return", found name "order"
Location: XPath syntax error at char 27 near {...x in /Order_1/Order_2 order...}:

在这种情况下如何设置order by

1 个答案:

答案 0 :(得分:0)

“order by”子句在XPath中不可用,仅在XQuery中可用。

改为使用XQueryCompiler。

XPath 3.0确实有一个sort()函数,但它可能不够用,例如它无法处理升序和降序键的混合。