我正在使用eXist的默认安装controller.xql和view.xq来使用eXist 4.2.1和XQuery3.1。
我有一个document.html,我将任何传入的url在结束时通过/doc/some-requested-doc-id结构来生成一个基于some-requested-doc-id的动态创建的页面。
因此,传入的url可以是http://localhost:8080/exist/apps/deheresi/doc/MS609-0001或http://localhost:8080/exist/apps/deheresi/doc/MS609-0001.xml。
他们受到同样的对待..。
在文件controller.xql中,我有一个匹配此请求的条件,它标识/doc/并使用传递给参数name="currentdoc"的函数清除预期的some-requested-doc-id。
[...]
else if (starts-with($exist:path, "/doc/")) then
(: strip out any extensions and rename global variable as .xml:)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/document.html">
<add-parameter name="currentdoc"
value="{concat(functx:substring-before-match($exist:resource,'[.]'),'.xml')}"/>
</forward>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
[...]请求的.html文件如下所示,它本身调用其他XQuery模板和/或在XQuery中动态创建的内容:
<div data-template="templates:surround" data-template-with="templates/site_wrapper.html" data-template-at="content">
<div data-template="document:title-bar"/>
<div class="col-sm-12">
<div class="col-md-2 sidebar">
<div data-template="document:doc-sidebar-sub1"/>
<div data-template="document:doc-sidebar-sub2"/>
<div data-template="document:doc-sidebar-sub3"/>
<div data-template="document:doc-sidebar-sub4"/>
</div>
<div class="col-md-10 document-view">
<div data-template="document:doc-xsl-docview"/>
</div>
</div>
</div>5 data-template="document:...通过<add-parameter>调用依赖于所提供的相同参数,例如,<div data-template="document:title-bar"/>调用:
declare function document:title-bar(
$node as node(),
$model as map(*),
$currentdoc as xs:string)
{
let $persid := person:person-name(data(doc(concat($globalvar:URIdata,$currentdoc))/tei:TEI/tei:text//tei:persName[@role="dep"]/@nymRef))
let $doctypeen := data(doc(concat($globalvar:URIdata,$currentdoc))/tei:TEI/tei:text//tei:div[@type="doc_type"]/@subtype)
let $x :=
<div class="col-md-12 document-title">
<h2><span class="en">{$doctypeen}: </span><span class="fr">{document:doc-type-french($doctypeen)} : </span>{$persid}</h2>
</div>
return $x
}; 即使我硬编码模块controller.xql中的参数
<add-parameter name="currentdoc" value="MS609-00001.xml"/>我仍然得到相同的错误,如果我硬编码模板调用中的参数,就不会发生这种情况:
The actual cardinality for parameter 3 does not match the
cardinality declared in the function's signature:
document:title-bar($node as node(), $model as map,
$currentdoc as xs:string) item()*.
Expected cardinality: exactly one, got 0.“预期基数”表示参数没有进入函数?
编辑:
如果我将上述函数中的参数顺序更改为
declare function document:title-bar(
$currentdoc as xs:string,
$node as node(),
$model as map(*))我得到了一个不同的错误:
Supplied argument 2 of function:
document:title-bar($currentdoc as xs:string,
$node as node(), $model as map) item()* does not
match required type. Required type node(), got map. `在此之前,非常感谢您。
发布于 2018-10-30 18:51:17
需要将<add-parameter>指令移到第二个<forward>指令中,以便modules/view.xql能够访问该参数。控制器的这个片段的修正版本是:
else if (starts-with($exist:path, "/doc/")) then
(: strip out any extensions and rename global variable as .xml:)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/document.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql">
<add-parameter name="currentdoc" value="{concat(functx:substring-before-match($exist:resource,'[.]'),'.xml')}"/>
</forward>
</view>
</dispatch>模板文档也显示了这一点--参见“设置”部分下的第二个代码示例:https://exist-db.org/exist/apps/doc/templating#D3.35。
(你提到的答案中有一个错误-我现在已经改正了。很抱歉,谢谢您的详细测试和清晰的问题!)
https://stackoverflow.com/questions/53067680
复制相似问题