Обработка неопределенного числа внешних переменных - PullRequest
1 голос
/ 27 марта 2019

Я использую baseX в среде REST, и я застрял, пытаясь запустить скрипт .xq с неопределенным числом переменных GET (может быть 1, но может быть 10). Я хотел бы сделать свой скрипт 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>

Спасибо!

1 Ответ

0 голосов
/ 27 марта 2019

нашел это здесь (см. Функцию 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 ... :)
};
...