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

  • Home
  • SEARCH
  • 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 1108275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:03:29+00:00 2026-05-17T02:03:29+00:00

I’m a little bit confused concerning variable updates in XQuery: On [1] it says:

  • 0

I’m a little bit confused concerning variable updates in XQuery:
On [1] it says:

Variables can’t be updated. This means you can’t write something like let $x := $x+1. This rule might seem very strange if you’re expecting XQuery to behave in the same way as procedural languages such as JavaScript. But XQuery isn’t that kind of language, it’s a declarative language and works at a higher level. There are no rules about the order in which different expressions are executed (which means that the little yellow triangle that shows the current execution point in the Stylus Studio XQuery debugger and XSLT debugger can sometimes behave in surprising ways), and this means that constructs whose result would depend on order of execution (like variable assignment) are banned.

I’m wondering if there is really no way to reliable update a variable? Maybe I’m just to used to those things in other languages, but I can’t really imagine / believe it 😉

[1] http://www.stylusstudio.com/xquery_flwor.html, second paragraph below the screenshots of the chapter “L is for LET”

UPDATE:
I have to add a question to this: Shouldn’t it be possible to update an existing variable in an if statement because in this case the order of execution is clear? I guess you just aren’t allowed to use something like $x = $x+1 in a loop?

  • 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-05-17T02:03:29+00:00Added an answer on May 17, 2026 at 2:03 am

    You are describing immutability, a feature of functional languages. It’s true; once a variable is set to a value, it cannot be set to something else.

    Immutability has many benefits. In particular, concurrent programming is made much easier.

    In the case of loops, what happens is that a new variable is created each time through the loop, replacing the original one. So immutability still holds. This is explained in detail in the article you linked:

    Isn’t there a variable being updated
    when you write something like the
    following?

    for $v in //video
    let $x := xs:int($v/runtime) * xdt:dayTimeDuration("PT1M")
    return concat($v/title, ": ", 
          hours-from-duration($x), " hour(s) ",
          minutes-from-duration($x), " minutes")
    

    (This query shows the running time of
    each video. It first converts the
    stored value from a string to an
    integer, then multiplies it by one
    minute (PT1M) to get the running time
    as a duration, so that it can extract
    the hours and minutes components of
    the duration. Try it.)

    Here the variable $x has a different
    value each time around the XQuery for
    loop. This feels a bit like an update.
    Technically though, each time round
    the for loop you’re creating a new
    variable with a new value, rather than
    assigning a new value to the old
    variable.

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

Sidebar

Related Questions

No related questions found

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.