我想在XML文件上执行一个xQuery文件;在编译查询时,我有以下错误。我不理解这个“上下文项”错误。
代码(示例)
String xmlFileName = "D:/fichierContenu.XML";
FileInputStream XmlStream = new FileInputStream(xmlFileName);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
FileInputStream fis = new FileInputStream(xmlFileName);
InputSource is = new InputSource(fis);
Document doc = builder.parse(is);
Element element = doc.getDocumentElement();
InputStream queryStream = queryStream = new FileInputStream("D:/TestsAuto.xq");
Processor proc = new Processor(false);
XQueryCompiler comp = proc.newXQueryCompiler();
XQueryExecutable exp = comp.compile(queryStream); XQuery
declare function local:checkRefTest() as xs:string {
(:text and explication here. :)
let $REFTEST := /dmodule/descendant::REFTEST ***(=> line 363 HERE)***
return
let $refTestKO :=
for $item in $REFTEST
return
if(fn:string-length($item/@RefTest)= 13) then
let $RefTest := fn:substring($item/@RefTest, 1, 6)
return
if ($RefTest = " ") then
if(fn:exists($item/@refval) and fn:exists($item/@refval2)) then
()
else
()
else
()
else
$item
return
if(fn:empty($refTestKO)) then
"OK"
else
fn:concat("NOK : test here ", "'",fn:string-join($refTestKO/@RefTest, "', '"),"'")
};误差
在没有systemId:XPDY0002: '/‘的模块的第363行上出错,无法选择包含上下文项的树的根节点:上下文项是在线程"main“net.sf.saxon.s9api.SaxonApiException中未定义的异常:无法选择包含上下文项的树的根节点:上下文项在由: net.sf.saxon.trans引起的net.sf.saxon.s9api.SaxonApiException at utils.xquery.essai.main(essai.java:92)处未定义引导“/”不能选择包含上下文项的树的根节点:上下文项在net.sf.saxon.expr.SingleNodeExpression.typeCheck(SingleNodeExpression.java:29) at net.sf.saxon.expr.parser.ExpressionVisitor.typeCheck(ExpressionVisitor.java:206)时未定义
你能给我解释一下或者给我看一段能让我解决这个问题的代码吗?
我的问题是什么?
发布于 2017-01-17 17:01:42
根据https://www.w3.org/TR/xquery-30/#FunctionDeclns,对于用户定义的函数,“它的上下文项静态类型组件是不存在的”。因此,我认为您的代码声明一个函数,但试图访问/,假设上下文节点无法工作,您将需要为该函数声明一个参数,并在调用该函数并使用declare function local:checkRefTest($input) as xs:string { (:text and explication here. :) let $REFTEST := $input/dmodule/descendant::REFTEST时传递一个节点。
https://stackoverflow.com/questions/41701877
复制相似问题