代码之家  ›  专栏  ›  技术社区  ›  Roberto Fernandez Diaz

使用existDB中的模板时出现异常

  •  0
  • Roberto Fernandez Diaz  · 技术社区  · 8 年前

    我正在尝试使用existDB将参数传递给应用程序,我的问题是在使用模板时,它会给我以下错误:

    templates:NotFound No template function found for call  app:getBusPorMatricula [at line 189, column 85, source: C:\Users\rober\Documents\eXist\webapp\WEB-INF\data\expathrepo\shared-0.4.0\content\templates.xql]
    In function:
        templates:call(item(), element(), map) [135:36:C:\Users\rober\Documents\eXist\webapp\WEB-INF\data\expathrepo\shared-0.4.0\content\templates.xql]
        templates:process(node()*, map) [146:81:C:\Users\rober\Documents\eXist\webapp\WEB-INF\data\expathrepo\shared-0.4.0\content\templates.xql]
        templates:process(node()*, map) [146:81:C:\Users\rober\Documents\eXist\webapp\WEB-INF\data\expathrepo\shared-0.4.0\content\templates.xql]
        templates:process(node()*, map) [146:81:C:\Users\rober\Documents\eXist\webapp\WEB-INF\data\expathrepo\shared-0.4.0\content\templates.xql]
        templates:process(node()*, map) [462:17:C:\Users\rober\Documents\eXist\webapp\WEB-INF\data\expathrepo\shared-0.4.0\content\templates.xql]
        templates:surround(node(), map, xs:string, xs:string?, xs:string?, xs:string?) [34:9:C:\Users\rober\Documents\eXist\webapp\WEB-INF\data\expathrepo\shared-0.4.0\content\templates.xql]
        templates:call-with-args(function, function*, element(), map) [208:13:C:\Users\rober\Documents\eXist\webapp\WEB-INF\data\expathrepo\shared-0.4.0\content\templates.xql]
        templates:process-output(element(), map, item()*, element()) [205:9:C:\Users\rober\Documents\eXist\webapp\WEB-INF\data\expathrepo\shared-0.4.0\content\templates.xql]
        templates:call-by-introspection(element(), map, map, function) [187:28:C:\Users\rober\Documents\eXist\webapp\WEB-INF\data\expathrepo\shared-0.4.0\content\templates.xql]
        templates:call(item(), element(), map) [135:36:C:\Users\rober\Documents\eXist\webapp\WEB-INF\data\expathrepo\shared-0.4.0\content\templates.xql]
        templates:process(node()*, map) [131:51:C:\Users\rober\Documents\eXist\webapp\WEB-INF\data\expathrepo\shared-0.4.0\content\templates.xql]
        templates:process(node()*, map) [88:9:C:\Users\rober\Documents\eXist\webapp\WEB-INF\data\expathrepo\shared-0.4.0\content\templates.xql]
        templates:apply(node()+, function, map?, map?) [45:5:C:\Users\rober\Documents\eXist\webapp\WEB-INF\data\expathrepo\shared-0.4.0\content\templates.xql]
    

    我实际拥有的代码是这个,我拥有所有在你创建应用程序时自动生成的代码,除了这些文件:

    应用程序xql:

    xquery version "3.0";
    
    module namespace app="http://gijonapp1.es/templates";
    
    
    declare namespace bus="http://docs.gijon.es/sw/busgijon.asmx";
    
    import module namespace templates="http://exist-db.org/xquery/templates" ;
    import module namespace config="http://gijonapp1.es/config" at "config.xqm";
    
    (:~
     : This is a sample templating function. It will be called by the templating module if
     : it encounters an HTML element with an attribute data-template="app:test" 
     : or class="app:test" (deprecated). The function has to take at least 2 default
     : parameters. Additional parameters will be mapped to matching request or session parameters.
     : 
     : @param $node the HTML node with the attribute which triggered this call
     : @param $model a map containing arbitrary data - used to pass information between template calls
     :)
    declare function local:getNumeroBusesFuncionando()
    {
        let $numero:=count(doc('http://datos.gijon.es/doc/transporte/busgijontr.xml')//bus:posicion)
        return $numero
    };
    
    declare function local:getBusesFuncionando()
    {
        <buses numero="{local:getNumeroBusesFuncionando()}">{
        for $bus in doc('http://datos.gijon.es/doc/transporte/busgijontr.xml')//bus:posicion
        order by xs:integer($bus/bus:idlinea)
        return <bus>{$bus/bus:matricula,$bus/bus:idlinea,$bus/bus:idtrayecto,$bus/bus:utmx,$bus/bus:utmy}</bus>}
        </buses> 
    };
    
    declare function app:showMenu($node as node(), $model as map(*)){
        <div>
            <ul>
                <li><a href="./busesFuncionando.html">Buses Funcionando</a></li>
                <form action="./busPorMatricula.html">
                Inserte la matricula del autobus a buscar :
                    <input type="text" name="matricula"/>
                    <input type="submit" value="Buscar"/>
                </form>
            </ul>
        </div>
    };
    
    declare function app:showBusFuncionando($node as node(), $model as map(*)) {
    
        <div>
             <h2> Buses funcionado a las {hours-from-time(current-time())}:{minutes-from-time(current-time())}</h2>
    
            <ul>
    
                    {
                        for $bus in local:getBusesFuncionando()//bus
                        return <li><b>Linea :{$bus/bus:idlinea}</b> Trayecto : {$bus/bus:idtrayecto} Matricula : {$bus/bus:matricula} Posicion : {$bus/bus:utmx},{$bus/bus:utmy}</li>
                    }
            </ul>
        </div>
    
    };
    
    (: !!!!!The PROBLEM is HERE !!!!:)
    
    declare function app:getBusPorMatricula($node as node(), $model as map(*))
    {
        let $matricula:=request:get-parameter('matricula', '')
    
        let $bus :=doc('http://datos.gijon.es/doc/transporte/busgijontr.xml')//bus:posicion[bus:matricula=$matricula]
       return
        <p>asd</p>
    
    };
    

    以下是使用模板的页面:

    index.html:

     <div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content">
            <h1> Menu </h1>
            <div data-template="app:showMenu"/>
        </div>
    

    busPorMatricula.html:

    <div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content">
        <h1> Bus con matricula </h1>
        <div data-template=" app:getBusPorMatricula" data-template-matricula="{request:get-parameter('matricula', ''}"/>
    </div>
    

    我想做的是给我一个登记号码,显示一些有这个号码的公交车的信息

    谢谢你的帮助

    1 回复  |  直到 8 年前
        1
  •  1
  •   Roberto Fernandez Diaz    8 年前

    我发现了错误,它在“busPorMatricula.html”中的html代码中

    数据模板的内容中有一个空格,这就是问题所在。

    我希望它能帮助其他人,我花了大约4个小时来寻找比这更复杂的事情。