1

我在 REST 环境中使用 baseX 并且我很难尝试运行具有未定义数量的 GET 变量(可能是 1 但可能是 10)的 .xq 脚本我想让我的 xq 脚本通用并独立构建我的查询。有没有办法实现这一点,使用数组或发送不同的变量,或者我不知道如何?


这是我的 API 调用

http://basex:8984/rest/?run=WEB-INF/data/test.xq&$tag=p&value=sciences&tag2=p&value2=test&tag3=testdzq

这是我的text.xq

declare variable $tag external;
declare variable $value external;

declare variable $tag2 external;
declare variable $value2 external;

<documents>
  {for $doc in collection("testdb2")
    where $doc//*[name() eq $tag]/text()[matches(., $value )]
      and  $doc//*[name() eq $tag2]/text()[matches(., $value2 )]

    return <doc>{$doc//titleStmt/title/text()}</doc>
  }
</documents>

谢谢 !

4

1 回答 1

0

在这里找到这个(见 http-params 函数)https://www.balisage.net/Proceedings/vol18/print/Murray01/BalisageVol18-Murray01.html

(: BaseX example :)

(: In the controller ... :)
module namespace c = "http://balisage.net/ns/Bal2016murr0319/controller";
import module namespace request = "http://exquery.org/ns/request";
import module namespace item = "http://balisage.net/ns/Bal2016murr0319/views/item" at "views/item.xqm";

(:~ Returns a map containing the HTTP request parameters. :)
declare function c:http-params()
as map(*)
{
  map:merge(
    for $name in request:parameter-names()
    let $value := request:parameter($name)
    return map:entry($name, $value)
  )
};

(:~ Calls the appropriate view, based on user input. :)
declare function c:get-view()
as element(html)
{
  (: get HTTP request parameters :)
  let $params := c:http-params()
  return
    if (map:get($params, "id")) then
      (: the presence of "id" indicates that the user is requesting the item-level page for this unique identifier :)
      (: call the item-level view :)
      item:get-html($params)
    else if ... (: call some other view :)
    else if ... (: call some other view :)
    else (: call the view for the home page ... :)
};
于 2019-03-27T14:22:00.953 回答