我需要使用计数器来记住我处理了多少个节点。所以我定义了一个全局变量$classCounter。由于一些未知的原因,我从zorba得到一个错误:
test.xqy>:15,9: error [zerr:XSST0004]: "local:owlClassNameBuilerHelper": function declared nonsequential but has sequential body我真的不明白这个错误是什么意思。如何在XQuery中实现全局计数器?
整个xqy文件是:
declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
declare namespace owl="http://www.w3.org/2002/07/owl#";
declare namespace xsd="http://www.w3.org/2001/XMLSchema#";
declare namespace rdfs="http://www.w3.org/2000/01/rdf-schema#";
import module namespace functx="http://www.functx.com";
declare variable $srcDoc:="test_xsd.xml"; (:need to adjust the input XSD file here:)
declare variable $defaultXMLNS:="http://www.test.com#";
declare variable $defaultXMLBase:=$defaultXMLNS;
declare variable $classCounter:=0;
declare function local:owlClassNameBuilerHelper($pnode as node()*)
as xs:string?
{
$classCounter:=classCounter+1;
let $tmp:=""
return
(
"haha"
(:if(functx:if-empty($pnode/@name, "-1")!="-1") (:if the name attr doesn't exist:)
then data($pnode/ancestor::element[1]/@name) (:get the name attr of first ancestor named element:)
else data($pnode/@name):)
)
};
element rdf:RDF
{
namespace {""} {$defaultXMLNS},
namespace {"owl"} {"http://www.w3.org/2002/07/owl#"},
namespace {"xsd"} {"http://www.w3.org/2001/XMLSchema#"},
namespace {"rdfs"} {"http://www.w3.org/2000/01/rdf-schema#"},
attribute xml:base {$defaultXMLBase}
}命令行:
zorba -i -f -q test.xqy发布于 2016-03-21 18:19:11
我需要使用一个计数器来记住我处理了多少个节点。
首先,XQuery是一种函数式编程语言。这是一个完全不同的处理模型:你不能“记住”你已经“处理”的东西,因为没有记忆,也没有时间维度。函数是数学函数,它们不能有像更新全局变量那样的副作用。
现在,错误消息提示我,您正在使用的特定XQuery处理器(Zorba)具有允许您脱离纯函数式编程模型的扩展;但是您错误地使用了这些扩展。特别是,如果你想要一个函数有副作用,那么你就必须声明这个函数。您必须在Zorba文档中查找如何做到这一点,因为没有标准。
https://stackoverflow.com/questions/36126104
复制相似问题