处理未定义数量的外部变量

Handling undefined number of external variables

我在 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>

谢谢!

在这里找到这个(参见 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 ... :)
};