Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8616729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:41:32+00:00 2026-06-12T05:41:32+00:00

I’m a beginner in xquery and I hope you can help me with an

  • 0

I’m a beginner in xquery and I hope you can help me with an easy explanation. I’m using BaseX 7.0.1.

I have a dictionary.xml file that looks like this :

<doc>
    <entry>
        <vedette>je</vedette>
        <variante>je</variante>
        <variante>j'</variante>
        <partiedudiscours>pronom</partiedudiscours>
    </entry>
</doc>

And I have another malone_fr.xml file that contains the text that I’d like to annotate, that looks like this :

<doc>
    L’Opportunité 
    Par : Walter Malone (1866-1915)
    Ils ont mal conclu ceux qui disent que je ne reviendrai plus
    Quand une fois j’ai frappé à ta porte et ne t’ai pas rencontré,
</doc>

So I’d like to compare the content of the < variante > part of dictionary.xml with my text, and markup the text with the content of < partiedudiscours >.
So far, I’ve been able to do that with this code :

let $comp := data(for $j in tokenize(for $i in db:open('malone_fr')/doc return $i,"\n") 
return tokenize($j," "))
for $aa in $comp
return
for $lemme in db:open('dictionnaire')/doc/entry
return
let $oldName :=$aa
return
if ($oldName= $lemme/variante)
then 
let $newName := element  {$lemme/partiedudiscours}  {$aa}
return
for $bb in $comp
return
if ($bb=$oldName)
then $newName 
else ($bb)
else ()

That gives me the following result:
[first iteration]

L’Opportunité  Par : Walter Malone (1866-1915) Ils<verbe>ont</verbe> mal conclu ceux qui disent que je ne reviendrai plus

[second iteration]

L’Opportunité  Par : Walter Malone (1866-1915) <pronom>Ils</pronom>ont mal conclu ceux qui disent que je ne reviendrai plus

As you can see, it only shows the result per word by iteration, whereas I need a result with the whole text annotated like:

L’Opportunité  Par : Walter Malone (1866-1915) <pronom>Ils</pronom><verbe>ont</verbe> <adverbe>mal</adverbe> <verb>conclu</verb> 

Etc.
I don’t know how I can deal with the for-loop to do that.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:41:33+00:00Added an answer on June 12, 2026 at 5:41 am

    I think your solution is a little more complicated than it needs to be. You should be able to do this in one loop. Using XPath to perform the lookup – instead of explicitly looping over all the values in your dictionary – will allow your database to optimize for faster retrieval of the dictionary data.

    let $toks := data(
        for $i in db:open('malone_fr')/doc 
        return tokenize($i,"\s"))
    for $t in $toks
    return
        let $e := $dict/entry[variante = $t]    
        return
            if ($e)
            then (element { $e/partiedudiscours } { $t }, text{" "})
            else ($t, text{" "})
    

    Also, the tokenize() step discards spaces, so no spaces exist in your output sequence. It will only appear spaced because that is typically the default method of rendering a sequence of atomic types; however, as you can see from your test output, spaces are not rendered around elements. In the above solution I added very basic space handling so elements are also correctly spaced. You can remove the text{" "} nodes if they are not needed.

    Update: added @DennisKnochenwefel’s suggestion

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.