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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:34:56+00:00 2026-05-16T18:34:56+00:00

I have an XSLT script which I would like to number things sequentially each

  • 0

I have an XSLT script which I would like to number things sequentially each time I call a template. So a very abbreviated version of it looks a bit like:

<xsl:call-template name="insertHeader" />
<xsl:for-each ...>  
    <xsl:call-template name="insertHeader" />
    ...
</xsl:for-each>
<xsl:call-template name="insertHeader" />

<xsl:template name="insertHeader>
    This is item number <xsl:value-of select="$numberOfInvocations />
</xsl:template>

So obviously that $numberOfInvocations thing doesn’t work, and in XSLT you can’t increment a global counter variable which would seem like an obvious approach in a procedural language. I would like it to print out 1 the first time that template is called, 2 the second, etc. How should I go about doing this? Is this even remotely possible in XSLT?

Thanks 🙂

Edit: So there have been a couple of comments that this isn’t clearly defined enough. What I want to do is label a series of tables in the (HTML) output. The most obvious way I see of doing this is to call a function (you can probably tell that I am not an XSLT wizard here) that will automatically increment the number each time. I think the reason this seems so hard is because it’s the XSLT itself that defines where these tables appear rather than the input.

This extra info may not be of that much use though since Dimitre’s answer makes it sound rather like this is never going to work. Thanks anyway 🙂

  • 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-16T18:34:57+00:00Added an answer on May 16, 2026 at 6:34 pm

    In a functional language as XSLT there is no “order of computation” defined.

    Therefore, trying to number the “computations” by their ordering “in time” isn’t meaningful and if attempted will often produce surprising results.

    For example, nothing restricts <xsl:apply-templates> to apply templates in the same order in time as the document order of the nodes in the selected node-list. These could be done in parallel, meaning in any order.

    Many XSLT processors perform lazy evaluation which means that a certain XSLT instruction will only be evaluated when it is really needed and not according to its textual order in the XSLT stylesheet. Often some instructions are not executed at all.

    Sometimes the optimizer will execute a given XSLT instruction twice because it decided to discard the first result in order to optimize space utilization.

    The requested numbering can be produced using recursion (generally) and continuation-passing style CPS or Monads (more specifically).

    The FXSL library (both version 1 — for XSLT 1.0 and version 2 — for XSLT 2.0) contains templates that can be used to organize such numbering: foldl, foldr, iter, iterUntil, scanl, scanr, …, etc.

    Whenever the problem is precisely defined (which is not the current case), such numbering can be produced but be warned about the results.

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

Sidebar

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.