Xquery eXist db通过controller.xql(URL映射)向模板传递参数

Xquery eXist db通过controller.xql(URL映射)向模板传递参数,xquery,exist-db,Xquery,Exist Db,我正在使用eXist默认安装的controller.xql和view.xq使用eXist db 4.2.1和Xquery 3.1 我有一个document.html,我将任何带有/doc/一些请求的doc id结构的传入url传递给它,以根据一些请求的doc id生成一个动态创建的页面 因此,传入的url可以是http://localhost:8080/exist/apps/deheresi/doc/MS609-0001或 http://localhost:8080/exist/apps/deh

我正在使用eXist默认安装的
controller.xql
view.xq
使用eXist db 4.2.1和Xquery 3.1

我有一个
document.html
,我将任何带有
/doc/一些请求的doc id
结构的传入url传递给它,以根据
一些请求的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”

即使我硬编码模块中的参数
controller.xql

 <add-parameter name="currentdoc" value="MS609-00001.xml"/>
“预期基数”表示参数没有进入函数

编辑:

如果我将上述函数中的参数顺序更改为

 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. `
非常感谢。

代码>


(您引用的答案中有一个错误,我现在已经更正了。非常抱歉,感谢您的全面测试和清晰的问题!)

您能否确认控制器中设置的参数名称与
文档:title-bar()
函数签名中的变量名称相同?在这里的示例代码中,它们是相同的(它们都是
currentdoc
),但我只是想检查一下,在您的系统中,出现错误的情况也是如此。(同样,对于这个问题来说,一些无关紧要的东西:在硬编码的
示例中,在
.xml
之后有一个尾随单引号(
'
))是的,事实上,以上所有内容都是从我的代码复制粘贴的。我删除了单引号并重新测试了相同的结果,谢谢(现在更新到上面)。这是项目的.xar:相关文件名与上面描述的完全相同。非常好。拥有.xar是非常有帮助的。谢谢你,它很有效!一个问题:是否存在引用应用程序路径的系统“常量”?例如,如果安装在
http://localhost:8080/exist/apps/
而应用程序
deheresi
是当前环境,“常量”将返回“”?我见过一些解决方案,它们将
系统:get-module-load-path()
…看看你的应用程序的
模块/config.xqm
是否声明了一个全局变量,
$config:app root
。动态确定应用程序的安装路径。
 <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. `
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>