如何在Saxon的Java上“for ... order by”

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

这是this question的后续行动。

我打电话:

XQueryCompiler compiler = processor.newXQueryCompiler();
// 21 of the following
xPath.declareNamespace(prefix, uri);
xPath.compile("for $n in '/def:System/def:Securities[def:AssetType != 50]' order by $n/'def:RiskLevel' return $n");
XQueryEvaluator selector = exe.load();
selector.setContextItem(xmlDocument);
// exception thrown on this:
selector.evaluate();

我得到:net.sf.saxon.s9api.SaxonApiException:'/'的第一个操作数的必需项类型是node();提供的值具有项类型xs:string

我猜'/ def:系统/ def:证券[def:AssetType!= 50]'需要成为一个节点 - 我该怎么做?而且,它会使它成为一个节点,然后将其减少到一个节点而不是返回与查询匹配的所有节点吗?

此查询可能很复杂,因为“节点/节点[@attr ='5] / node / not [node ='dave'] / node / @ atr”

更新:查询“for $ n in / def:System / def:Securities [def:AssetType!= 50] order by $ n /'def:RiskLevel,def:SecurityDesc'return $ n”我得到相同的异常。

saxon
1个回答
0
投票

查询中的那些单引号是虚假的。你将$ n绑定到字符串'/def:System/def:Securities[def:AssetType != 50]',错误是当$n/xxx是一个字符串时你不能使用$n

© www.soinside.com 2019 - 2024. All rights reserved.