Search code examples
xqueryexist-db

Can't display text into paragraphs using XQuery and eXist-db


I have to figure out how to display paragraphs that each word in the paragraph has its own hover function(comment).

enter image description here

Here is how the page looks like right now. I want to display the left text in paragraphs as I have in the right text. the first one is the translation and the second one is the original text. The thing is that I need to have a hover function on the first text for every word. It is already done this is how it looks and it's working for each word: enter image description here

so to explain it better we have paragraphs and every word in paragraphs has to have the hover function with some comments. The main task is to display the words in paragraphs and not like it is the first picture, but like this: enter image description here

This is my code right now which displays text like it's in the first picture, so not in paragraphs but every word on a new line with hover function:

declare function letter:text_orig($node as node(), $model as map())
{
    let $resource := collection('/db/apps/Tobi-oshki/data')
    let $xml_id := letter:text_people('/db/apps/Tobi-oshki/data')
    for $rs in $resource//tei:rs
    for $id in $xml_id
        return
            if (data($rs/@key) eq $id)
            then 
                <html>

             <div data-toggle="tooltip" data-placement="top" 
             title="{letter:text_lem(data($rs/@key))}"> {$rs}</div>

               </html>
             else
                "" };

the XML file looks like this:

 <div type="original" xml:lang="ka">
        
            <pb f="1r" n="1" xml:id="pb-orig-1r-1" facs="#zone-pb-1r-1"/>
            
            <lb n="2" xml:id="l-1"/>
            <ab>[7125.5]<rs type="pers" key="320">ენემ<supplied reason="lost">ეს</supplied>[7125.1]არისთა</rs>,
            
                <rs type="pers" key="1643">მეფისა </rs>
                
                <rs type="pers" key="251">თეზბეთ</rs>,
               
                <rs type="pers" key="243">ზემო-კერძო</rs>
                
                <rs type="pers" key="245">ასერსა</rs>.
            </ab>

so ab tag is a paragraph and rs tag is a word.

Do you have any idea how can I display paragraphs with each word having its hover function?


Solution

  • It sounds to me as if you want e.g.

    for $ab in $resource//tei:ab
    return
      <p>
      {
        for $rs in $ab/tei:rs
        return <span data-toggle="tooltip" data-placement="top" 
                 title="{letter:text_lem(data($rs/@key))}">{$rs/data()}</span>
      }
      </p>
    

    I haven't figured out what the id check is doing so you might need to adjust the above, but it "maps" an ab to a p element.