我正在使用eXist的默认安装controller.xql
和view.xq
使用eXist-db 4.2.1和Xquery 3.1。
我有一个document.html
,最后我将传入以/doc/some-requested-doc-id
结构化的所有传入URL传递到其中,以基于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/
并使用function清除预期的some-requested-doc-id
,该depend on the same parameter provided传递给参数{ {1}}:
name="currentdoc"
所请求的.html文件如下,该文件本身调用其他HTML模板和/或在XQuery中动态创建的内容:
[...]
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>
[...]
通过 <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:...
呼叫https://css-tricks.com/zooming-squishes/,例如<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(*))
非常感谢。
答案 0 :(得分:1)
<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。
(您所引用的答案有一个错误-我已经纠正了。抱歉,谢谢您的全面测试和明确表达的问题!)