Siddhu
Siddhu

Reputation: 327

For loop to get Sequence of number for n number of nodes

If i'm having 'n' number of nodes and i want to assign a number from starting of the node to 'n' number of nodes. example:

<entity>
  <result>
    <seq>1</seq>
  </result>
  <result>
    <seq>2</seq>
  </result>
  <result>
    <seq>3</seq>
  </result>
  ....
  ....
  ....
  <result>
    <seq>n</seq>
  </result>
</entity>

Upvotes: 0

Views: 2639

Answers (2)

Gary Russo
Gary Russo

Reputation: 355

Use the at keyword to count the iteration.

let $list := (20, 23, 25, 24, 22, 21)

return
  <entity>
  {
    for $n at $seq in $list
      return
        <result><seq>{$seq}</seq><value>{$n}</value></result>
  }
  </entity>

Upvotes: 1

Jens Erat
Jens Erat

Reputation: 38712

If the example is what you want as result, try this:

<entity>
    {
        for $n in 1 to 10
        return
            <result><seq>{$n}</seq></result>
    }
</entity>

Otherwise, rewrite your question so it contains

  • What do you want to achieve
  • What's the input
  • What's the expected output

Also, do you want to update you document (XQuery Update) or only enrich the output?

Upvotes: 2

Related Questions