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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:29:12+00:00 2026-05-10T15:29:12+00:00

How to get a counter inside xsl:for-each loop that would reflect the number of

  • 0

How to get a counter inside xsl:for-each loop that would reflect the number of current element processed.
For example my source XML is

<books>     <book>         <title>The Unbearable Lightness of Being </title>     </book>     <book>         <title>Narcissus and Goldmund</title>     </book>     <book>         <title>Choke</title>     </book> </books> 

What I want to get is:

<newBooks>     <newBook>         <countNo>1</countNo>         <title>The Unbearable Lightness of Being </title>     </newBook>     <newBook>         <countNo>2</countNo>         <title>Narcissus and Goldmund</title>     </newBook>     <newBook>         <countNo>3</countNo>         <title>Choke</title>     </newBook> </newBooks> 

The XSLT to modify:

<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>     <xsl:output method='xml' version='1.0' encoding='UTF-8' indent='yes'/>     <xsl:template match='/'>         <newBooks>             <xsl:for-each select='books/book'>                 <newBook>                     <countNo>???</countNo>                     <title>                         <xsl:value-of select='title'/>                     </title>                 </newBook>             </xsl:for-each>         </newBooks>     </xsl:template> </xsl:stylesheet> 

So the question is what to put in place of ???. Is there any standard keyword or do I simply must declare a variable and increment it inside the loop?

As the question is pretty long I should probably expect one line or one word answer 🙂

  • 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. 2026-05-10T15:29:13+00:00Added an answer on May 10, 2026 at 3:29 pm

    position(). E.G.:

    <countNo><xsl:value-of select='position()' /></countNo> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to get the total number of bytes that my computer has
I would like to get the generic information ( Counter class) of my CounterPersistence
I have a hidden input element that I am using as a counter to
I added a counter cache but can't get it to update. But I can
I want to get specific counters for processes that I have process id's for.
Get class from div inside an li and add to the same li. The
//Get width and resize another element $(document).ready(function() { function ResizeSearch(GridID, SearchID) { var eleWidth
When inside a class you have a private fiels and expose that field on
How do you get the length of the text inside a Mojo TextField? I'm
I have declared global variable named counter=0 on my index.html page inside head section

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.