regina
regina

Reputation: 1

URL mapping not working properly from controller.xql

I've been trying to forward the file to HTML template but it's not working. Here is the code in file.xql

{
for $resource in collection('/db/apps/myapp/data')
let $doc := request:get-parameter("filename", ())
let $uri := document-uri( root( $resource ) )

return
    <a href="{$uri}"> {document-uri( root( $resource ) )}</a>
};

and here is controller.xql

    if ($exist:path eq '') then
    <dispatch xmlns="http://exist.sourceforge.net/NS/exist">
        <redirect url="{request:get-uri()}/"/>
    </dispatch>
    
else if ($exist:path eq "/") then
    (: forward root path to index.xql :)
    <dispatch xmlns="http://exist.sourceforge.net/NS/exist">
        <redirect url="index.html"/>
    </dispatch>

else if (ends-with($exist:resource, ".html")) then
    (: the html page is run through view.xql to expand templates :)
    <dispatch xmlns="http://exist.sourceforge.net/NS/exist">
        <view>
            <forward url="{$exist:controller}/modules/view.xql"/>
        </view>
        <error-handler>
            <forward url="{$exist:controller}/error-page.html" method="get"/>
            <forward url="{$exist:controller}/modules/view.xql"/>
        </error-handler>
    </dispatch>
else if (contains($exist:path, "/data/")) then

    <dispatch xmlns="http://exist.sourceforge.net/NS/exist">

           <forward url="{$exist:controller}/templates/file.html"/>
        <view>
            <forward url="{$exist:controller}/modules/view.xql">
                <add-parameter name="filename" value="{$exist:resource}.xml"/>
            </forward>
        </view>
    </dispatch>

But it goes to URL "http://localhost:8080/db/apps/myapp/data/let001.xml" and not to "http://localhost:8080/db/apps/myapp/templates/file.html" Any ideas what is wrong in the code?

Upvotes: 0

Views: 39

Answers (0)

Related Questions