首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XPTY0002 contextItem

XPTY0002 contextItem
EN

Stack Overflow用户
提问于 2017-01-17 16:10:45
回答 1查看 212关注 0票数 1

我想在XML文件上执行一个xQuery文件;在编译查询时,我有以下错误。我不理解这个“上下文项”错误。

代码(示例)

代码语言:javascript
复制
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

代码语言:javascript
复制
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)时未定义

你能给我解释一下或者给我看一段能让我解决这个问题的代码吗?

我的问题是什么?

EN

回答 1

Stack Overflow用户

发布于 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时传递一个节点。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41701877

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档