0

I'm trying to show only the belows elements of a node by name.

In Xpath here is my statment: //akweny[parent::akwen/nazwa="Atlantycki"]

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

And here is my DTD

<?xml version="1.0" encoding="utf-8"?>
<!ELEMENT akweny (akwen+)>
<!ELEMENT akwen (nazwa, typ, powierzchnia, akweny?)>
<!ELEMENT nazwa (#PCDATA)>
<!ELEMENT typ (#PCDATA)>
<!ELEMENT powierzchnia (#PCDATA)>

And here is my Xquery statement

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

<table border="1" width="100%">
<th>Podrzędne</th><th>Nazwa</th><th>Typ</th><th>Powierzchnia</th><th>Edycja</th>
{
    (:DOBRE ZAPYTANIE
    for $x in doc('/db/Dane/akweny.xml/')//akweny[parent::akwen/nazwa="Atlantycki"]
    parent::akwen/nazwa="Atlantycki"]/text()
    :)

    for $x in doc('/db/Dane/akweny.xml/')//akweny[parent::akwen/nazwa="Atlantycki"]
    let $nazwa := $x/nazwa
    let $typ := $x/typ
    let $powierzchnia := $x/powierzchnia
        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>
};

For fast testing Xpath with my xml u can use this tool: http://www.online-toolz.com/tools/xpath-editor.php

The big problem is in Exist-DB data are displayed incorrectly.

My resultat is nothink... but it should be node parents...

I have no idea what I'm doing wrong. Please help me.

Brieg
  • 63
  • 13

1 Answers1

2

Before you start using eXist-db's templating system, you should test your XPath in eXide.

You refer to the document with /db/Dane/akweny.xml/. Though this gives no error, you should remove the last "/", since it is not part of the document name.

Then you should have a look at your XPath, //akweny[parent::akwen/nazwa="Atlantycki"]. Are you trying to find any akweny that have a parent akwen with a nazwa child with the value of "Atlantycki"? There is only one,

<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>

Or are your trying to retrieve something else?

Try entering

doc('/db/Dane/akweny.xml')//akweny[parent::akwen/child::nazwa eq "Atlantycki"]

in eXide and tune your XPath to get the results you want, by adding one step at a time.

Perhaps you are looking for something like this:

<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="Atlantycki"]
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>

When you have finished with this, remember that you have to call your app:PokazRodzica() function somewhere, for instance in index.html. The function in itself does not display anything (as wst wrote above).

Please correct the spelling in your title to "Error with display in eXist-db using XPath with XQuery".

  • That is correct i want retrive exactly what you provided. Then how i can display this table using HTML? Tite is now crrect. Sorry i writng this in 2:00 night o clock at my time... – Brieg Mar 05 '14 at 08:10
  • If you have generated a standard app using eXide, you just change your `…
    ` with mine in the function. In index.html, you should have something like `
    `. If you then call `http://localhost:8080/exist/apps/PokazRodzica/`, you should see your table. It doesn't look nice, but it's a start! - Your next task is of course to avoid hard-coding "Atlantycki" ….
    – Jens Østergaard Petersen Mar 05 '14 at 08:36
  • Hmm it dosen't show evrythink. Its show only 2 elements: `Północne morze 750 Batyckie morze 386` it dosen't show elements of `"Botnicka"` – Brieg Mar 05 '14 at 17:19
  • I looking for this: **I'm trying to find any akweny that have a parent akwen with a nazwa child with the value of "Atlantycki".** – Brieg Mar 05 '14 at 17:36
  • Jens Østergaard Petersen plz look at my DTD file. This should be more information about my problem. – Brieg Mar 05 '14 at 18:04
  • U can se here: https://drive.google.com/file/d/0B7vs-QT6iYaJaGlITGpEMTR0NzQ/edit?usp=sharing what it display using Exist-DB. So Exist-DB have got error(bug) with good display this function? – Brieg Mar 05 '14 at 18:12
  • Be a little more careful before you call something a bug! Is this what you want? Północne morze 750 Batyckie morze 386 Botnicka zatoka 117 – Jens Østergaard Petersen Mar 06 '14 at 01:42
  • Any sugestion for help some? – Brieg Mar 07 '14 at 18:56
  • Change `doc('/db/Dane/akweny.xml')//akweny[parent::akwen/nazwa="Atlantycki"]` to `doc('/db/Dane/akweny.xml')//akweny[ancestor::akwen/nazwa="Atlantycki"]`. – Jens Østergaard Petersen Mar 08 '14 at 16:31