exist-db cardinality for parameter

2019-07-11 07:24发布

I am new in exist-db and XQuery.

In exist-db I have this site map: The catalog "registranten" contains the catalog "data" (with xml-files) and the two files "regBasic.xql" and "regSearch.xql".

I am trying to search in the xml-files using the script regSearch.xql:

xquery version "3.0";

declare option exist:serialize "method=xhtml media-type=text/html";
declare variable $pageTitle := "Resultat";
declare variable $searchphrase := request:get-parameter("searchphrase", ());

<html>
    <head>
        <meta HTTP-EQUIV="Content-Type" content="text/html; charset=UTF-8"/>
        <title>{$pageTitle}</title>
    </head>
    <body>
        <h1>{$pageTitle}</h1>
        <p>Søgestreng eller søgeord: "{$searchphrase}"</p>
        <ul>
        {
            for $p in collection("/db/registranten/data")//grundtvig/indholdsregest/p[ft:query(., $searchphrase)]
            return
                <li>
                    from: {string(root($p)/grundtvig/filnavn)}<br/>
                    <i>$p</i>
                </li>
        }
        </ul>
    </body>
</html>

When I evaluate the script I get this error: "exerr:ERROR XPTY0004: The actual cardinality for parameter 2 does not match the cardinality declared in the function's signature: ft:query($nodes as node(), $query as item()) node(). Expected cardinality: exactly one, got 0. [at line 17, column 100, source: /db/apps/registranten/regSearch.xql]"

What does that mean and what is wrong with the script?

1条回答
2楼-- · 2019-07-11 07:53

Your $searchphrase variable is an empty sequence, which likely suggests that you did not set the request parameter which you are asking for with request:get-parameter().

查看更多
登录 后发表回答