0

I found some think about call function in function but i got this error:

NotFound No template function found for call app:PokazRodzica

But first. Here is my MAIN function

    declare function app:WyswietlAkweny($node as node(), $model as map(*), $nazwa as xs
    :string?) {

        <table border="1" width="100%">
        <th>Podrzędne</th><th>Nazwa</th><th>Typ</th><th>Powierzchnia</th><th>Edycja</th>
        {
            for $x in doc('/db/Dane/akweny.xml/')//akwen
            let $nazwa := $x/nazwa,
                $typ := $x/typ,
                $powierzchnia := $x/powierzchnia
                return <tr>
(:~ THIS DOSENT WORK :)
                    <th><a href="{app:PokazRodzica($nazwa)}"><img src="/exist/apps/Obrazki/lupa.jpg" alt="Podrzedny" /> KLIK</a></th>
                    <th bgcolor="#F46978">{$nazwa}</th>
                    <th>{$typ}</th>
                    <th>{$powierzchnia}</th>
                    <th>Edytuj</th>
                    </tr>
        }
        </table>
    };

And here is my function what i want to run when i press on image

declare function app:PokazRodzica($nazwa1 as xs:string?)  {


<table border="1" width="100%">
<th>Podrzędne</th><th>Nazwa</th><th>Typ</th><th>Powierzchnia</th><th>Edycja</th>
{
let $nodes := doc('/db/Dane/akweny.xml')//akweny[parent::akwen/nazwa=$nazwa1]
for $x in $nodes/*
let $nazwa := $x/nazwa/text()
let $typ := $x/typ/text()
let $powierzchnia := $x/powierzchnia/text()
    return 
       <tr>
        <th><img src="/exist/apps/Obrazki/lupa.jpg" alt="Podrzedny" /> {count($nazwa/text())} KLIK</th>
        <th bgcolor="#F46978">{$nazwa}</th>
        <th>{$typ}</th>
        <th>{$powierzchnia}</th>
        <th>Edytuj</th>
        </tr>
}</table>
};

And here is my XML file:

<?xml version="1.0" encoding="utf-8"?>
<akweny>
    <akwen>
        <nazwa>Atlantycki</nazwa>
        <typ>ocean</typ>
        <powierzchnia>106450</powierzchnia>
        <akweny>
            <akwen>
                <nazwa>Północne</nazwa>
                <typ>morze</typ>
                <powierzchnia>750</powierzchnia>
            </akwen>
            <akwen>
                <nazwa>Batyckie</nazwa>
                <typ>morze</typ>
                <powierzchnia>386</powierzchnia>
                <akweny>
                    <akwen>
                        <nazwa>Botnicka</nazwa>
                        <typ>zatoka</typ>
                        <powierzchnia>117</powierzchnia>
                    </akwen>
<akweny>
                        <akwen>
                        <nazwa>Botnicka</nazwa>
                        <typ>zatoka3</typ>
                        <powierzchnia>11777</powierzchnia>
                        </akwen>
</akweny>
                </akweny>
            </akwen>
        </akweny>
    </akwen>
    <akwen>
        <nazwa>Spokojny</nazwa>
        <typ>ocean</typ>
        <powierzchnia>179700</powierzchnia>
    </akwen>
</akweny>

I call MAIN function like this:

<p class="app:WyswietlAkweny"/>

I'm trying to find any akweny that have a parent akwen with a nazwa child and child and infinity with the value of $nazwa1.

Brieg
  • 63
  • 13

1 Answers1

1

I think I understand the problem now. I'm suspect you want this function to be called and its value returned when the user clicks on this anchor tag while viewing the web page:

<a href="{app:PokazRodzica($nazwa)}">

This is not what's happening. When you output this anchor tag, anything in the AVT ({}) will be evaluated before returning. So this calls the function you referenced and stores its output literally in that attribute. What you need to is to reference an endpoint so the browser can call the function via the endpoint:

<a href="/call-app-PokazRodzica.xqy?value={$nazwa}">

Then in the endpoint script, call-app-PokazRodzica.xqy, accept a value parameter, and call your function:

app:PokazRodzica($value-param)

Now, when your user clicks on the anchor, it will call the endpoint and pass it the value. The browser will then return the results of the endpoint call.

wst
  • 11,681
  • 1
  • 24
  • 39
  • THis is almost done. In exist-db i got this error: HTTP ERROR 404 Problem accessing /exist/apps/AkwenyXML/call-app-PokazRodzica.xqy. Reason: Document /db/apps/AkwenyXML/call-app-PokazRodzica.xqy not found – Brieg Mar 05 '14 at 21:11
  • It'sa any chance to run this function i SAME page? – Brieg Mar 05 '14 at 21:17
  • @Brieg The issues you're encountering are mostly likely related to HTTP server configuration. And yes, you can have the endpoint call itself. – wst Mar 05 '14 at 22:50
  • 2
    More likely the path is mistaken …. @Brieg, please tell your teacher that he/she has to teach his/her students some basic XQuery first and practice how to set up an application without using the eXist-db templating framework - for those who know some programming (in other languages), the templating framework can be difficult to understand. And you really have to be a lot clearer in your questions if you want others to help you with you homework. And you should credit those who have helped you, not present code others have helped you with as your own. – Jens Østergaard Petersen Mar 06 '14 at 04:27