Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Plain Text by rodya ( 12 years ago )
xquery version "3.0";

declare namespace request="http://exist-db.org/xquery/request";
declare namespace util="http://exist-db.org/xquery/util";
declare option exist:serialize "method=xhtml media-type=application/xhtml+html";


let $add:=request:get-parameter("add", ""),
    $animalid:=request:get-parameter("animalid", ""),
    $delete:=request:get-parameter("delete", "")
return
    if ($add) then
            let $newanimal := 
                    <animal xml:id="id{util:uuid()}">
                      <specie>{request:get-parameter("specie", "")}</specie>
                      <title>{request:get-parameter("title", "")}</title>
                      <name>{request:get-parameter("name", "")}</name>
                      <description>{request:get-parameter("description", "")}</description>
                    </animal>
            return
                (
                    update insert $newanimal into /zoo,
                    response:redirect-to(xs:anyURI("http://localhost:8080/exist/apps/myapp2/"))
                )
                
    else if ($delete) then
        (
            update delete /zoo/animal[@xml:id=$delete],
            response:redirect-to(xs:anyURI("http://localhost:8080/exist/apps/myapp2/"))
        )
    else if ($animalid ) then
            let $id := request:get-parameter("animalid", ""),
                $animal := /zoo/animal[@xml:id=$id]
            return
                <html>
                    <p>
                        Имя: {$animal/name/text()} <br/>
                        Описание: {$animal/description/text()}
                    </p>
                </html>
        else 
            <html>
                <form method="GET">
                    Specie: <input type='text' name='specie'/><br/>
                    Title: <input type='text' name='title'/><br/>
                    Name: <input type='text' name='name'/><br/>
                    Description: <input type='text' name='description'/><br/>
                    <input type='submit' name='add' value="Добавить"/>
                </form>
            <ul>
            {
                for $animal in /zoo/animal
                return
                    <li>
                        <a href='?animalid={$animal/@xml:id}'>
                            {$animal/title/text()}
                        </a>
                        <a href='?delete={$animal/@xml:id}'>
                            Удалить
                        </a>    
                    </li>
            }
            </ul>
            </html>

 

Revise this Paste

Your Name: Code Language: