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 8174497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:28:31+00:00 2026-06-06T22:28:31+00:00

I want a solution for udnerstanding how to hold a real loop counter as

  • 0

I want a solution for udnerstanding how to hold a real loop counter as Java in xQuery, not a workaround for my particular simplified demo. I know in xQuery 3.0 there is a count reserved word for FLOWR structures but its useless pre-Saxon 9.something. Here my example.

     for $elem at $x in /Data/* return element Elem {       
            attribute Name   {concat('_',$x,'.',name($elem))},      
            (: ...10 lines of code... :)        
            for $subelem at $y in $elem/*       
            (: ...5 lets... :)      
            return element SubElemen {
               attribute Name {concat('_',$x,'.',$y,'_',name($subelement))},
               (...20 lines of other attrs and elements ...)
           for $subsubelem at $z in $subElem/SubSubElement
               let $absIterIndex := 'THIS IS WHAT IM LOOKING'
               let $subSubElemName := concat('_',$absIterIndex,'_',name($subElem))
            return
                                 element SubSubElem {
                 attribute Name {$subsubelem}, 
                   (..100 lines more playing with $x, $y, $absIterIndex, all lets for that iteration, attributes depending on them...)

The output is something like this (real data hidden and simplified)

 <Elem Name="_1.Name">
      <SubElem Name="_1.1_Name">
           <SubSubElem Name="_1.First"/>
           <SubSubElem Name="_2.Second"/>
           <SubSubElem Name="_3.Third"/>
      </SubElem Name="_1.1_Name">
      <SubElem Name="_1.2_Name">
           <SubSubElem Name="_4.Fourth"/>
           <SubSubElem Name="_5.Fifth"/>
           <SubSubElem Name="_6.Sixth"/>
           <SubSubElem Name="_7.Seventh"/>
      </SubElem Name="_1.1_Name">
  <Elem Name="_2.Name">
      <SubElem Name="_2.1_Name">
           <SubSubElem Name="_8.Eighth"/>
           <SubSubElem Name="_9.Ninth"/>
           <SubSubElem Name="_10.Tenth"/>
           <SubSubElem Name="_11.Eleventh"/>
      </SubElem Name="_2.1_Name">
      <SubElem Name="_2.2_Name"/>
  </Elem Name="_2.Name">
  <Elem Name="_3.Name">
      <SubElem Name="_3.1_Name">
           <SubSubElem Name="_12.Twelven"/>
      </SubElem Name="_3.1_Name">
      <SubElem Name="_3.2_Name"/>
  </Elem Name="_3.Name">     

This is a extension of a previous question Autoincremental auxiliar index var for XQuery nested loops, which I accepted the solution for the xQuery 3.0 counter, and then propose an alternative for manually doing it. But know i think the perspective is different and more concrete, and with a new example. If you think it should be deleted just tell it to me.

  • 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-06T22:28:32+00:00Added an answer on June 6, 2026 at 10:28 pm

    New question – new answer.

    But the principle remains the same: produce an unnumbered result first, then apply the numbering. This may require rewriting the result.

    Insert your code instead of the XML comment below.

    declare function local:renumber($number, $string)
    {
      replace($string, 'THIS IS WHAT IM LOOKING', string($number))
    };
    
    declare function local:renumber($subSubElems, $number, $nodes)
    {
      for $node in $nodes
      return
        typeswitch ($node)
        case attribute()              return attribute {node-name($node)} {local:renumber($number, $node)}
        case processing-instruction() return processing-instruction {name($node)} {local:renumber($number, $node)}
        case comment()                return comment {local:renumber($number, $node)}
        case text()                   return text {local:renumber($number, $node)}
        default (: element() :) return
          element {node-name($node)}
          {
            local:renumber
            (
              $subSubElems, 
              if ($subSubElems[. is $node]) then count($subSubElems[. << $node]) + 1 else $number, 
              ($node/@*, $node/node())
            )
          }
    };
    
    let $result := <result>{<!-- your code here -->}</result>
    return local:renumber($result//SubSubElem, 0, $result/node())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want a solution for tag:hover that is not working on ie6. My guess
I want to modify the solution for highlighting trailing whitespace described here by NOT
I want to know what is the best solution for creating ASP.NET HTTP Handler
I have the following situation (I know it doesn't sound real but I simplified
i want a solution for this , i want to delete a file which
I have 2 projects in my solution i want the build log of both
This is my first usage of jQuery. I just want a quick solution for
I want to find a programmatic solution using C++. I have a 900 files
I want implement in my software solution an VBA editor but in c# 3.0.
I want to create a Dynamic aspx Page in current solution through code-behind..forexample i

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.