Xquery function call self first without click and then after click function call self with Xpath

StackOverflow https://stackoverflow.com/questions/22211919

  •  10-06-2023
  •  | 
  •  

سؤال

The title is weird but ...

In Exist-db

How to call function on the same page normaly. Just display evrythink in XML and on click on the hiperlink call self again with XPath..

I have got this function. Meaby it's fully crapy... i quess...

declare function app:WyswietlAkweny($loc, $evtObj) {

    <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>
                <th><a href="TO THE PARRENT"><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>
};

Here is my XML

<?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>
            </akweny>
        </akwen>
        <akwen>
            <nazwa>Spokojny</nazwa>
            <typ>ocean</typ>
            <powierzchnia>179700</powierzchnia>
        </akwen>
    </akweny>

So the problem is when i click on "KLIK" it have to show ONLY find any element akweny that have a parent element akwen and repeat to the end elements with a nazwa child with the value of current click element akwen

In short when i select nazwa=Batyckie it should show all nodes below.

Any idea?

ps. nazwa=name in Polish language

هل كانت مفيدة؟

المحلول

I am not sure I can understand your XML or quite what you wish to navigate to, however regards hyper-linking from one query to another, it is just all straight-forward HTTP. e.g. you can do something like changing this from:

<th><a href="TO THE PARRENT"><img src="/exist/apps/Obrazki/lupa.jpg" alt="Podrzedny" /> KLIK</a></th>

to:

<th><a href="/exist/rest/db/myquery.xqy?search=parent&amp;current={util:node-id($x)}"><img src="/exist/apps/Obrazki/lupa.jpg" alt="Podrzedny" /> KLIK</a></th>

Obviously above you need to replace /db/myquery.xqy with the path of your XQuery. In your XQuery you can then use an if/else to decide whether it has been called with the parameters and take a different course of action. e.g.:

if(request:get-parameter("search", ()) eq "search" and request:get-parameter("current", ()))then
    let $current := util:node-by-id(doc("/db/Dane/akweny.xml"), request:get-parameter("current", ()))
    return
        $current (: TODO do something to find the parent instead! :)

else
    (: TODO whatever you are already doing :)

Whilst I have used util:node-id and util:node-by-id to link from one query to another, I would not really recommend this as these IDs are not stable. Instead you should add an ID to the XML of each record you are interested in addressing directly and use those.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top