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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:30:10+00:00 2026-05-21T19:30:10+00:00

I would like to know if we have something in XSL 2.0, equivalent to

  • 0

I would like to know if we have something in XSL 2.0, equivalent to a List in Java. I would like to recursively call a template 10 times and pass a input variable with name ‘mylist’. Within the template, I want to do operations like adding item to list, removing item from list, iterating over items within the list etc. I could see something like ‘sequence’ but i am not sure if it can be used to add, remove, iterate etc. Please share your ideas to implement this.

I tried using sequence with the help of the below reponse, I face some issues with syntax, like declaring an empty sequence. I want to print the sequence 1 2 3 4 5 6 7 8 9 10, using the insert-before or concat sequnce functions. Please help me fix the syntax.

  <xsl:stylesheet version="2.0" 
  xmlns:locator="http://ntr.lxnx.org"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
  <xsl:template match="/"> 
  <xsl:variable name="output">
  <xsl:call-template name="calculate-data"> 
                <xsl:with-param 
                    name="sequence" 
                    select=""/> 
                 <xsl:with-param 
                    name="count"  
                    select="1"/>
            </xsl:call-template> 
  </xsl:variable>
  <xsl:value-of select="output"></xsl:value-of>
  </xsl:template>  
  <xsl:variable name="main-root" as="document-node()" select="/"/>

  <xsl:template name="calculate-data">
<xsl:param name="sequence"/>
  <xsl:param name="count" select="0"/>
<xsl:if test="$count != 10">
                fn:insert-before($count as item()*,0 as xs:integer,$sequence as item()*)
                <xsl:call-template name="calculate-data"> 
                    <xsl:with-param 
                        name="sequence" 
                        select="$sequence"/> 
                     <xsl:with-param 
                        name="count"  
                        select="$count + 1"/>
                </xsl:call-template>              


</xsl:if> 
        </xsl:template>
        </xsl:stylesheet>
  • 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-21T19:30:11+00:00Added an answer on May 21, 2026 at 7:30 pm

    With the clarification that an instance of a sequence, as anything else in XPath/XSLT are immutable, the answer is positive:

    1. Iterating over a sequence:

      <xsl:for-each select="$seq">
       <!-- Whatever necessary code here -->
       <!-- . is the current item of the sequence-->
      </xsl:for-each>
      
    2. Add an item to a sequence (produces a new sequence that is the result of this operation):

         insert-before($target as item()*,
                       $position as xs:integer,
                       $inserts as item()*) as item()*
      

    Summary: Returns a new sequence constructed from the value of $target
    with the value of $inserts inserted at
    the position specified by the value of
    $position. (The value of $target is
    not affected by the sequence
    construction.)

    .3. Concatenation of two sequences (produces a new sequence that is the result of this operation):

       $seq1 , $seq2
    

    ..4. Remove an item from a sequence:

         remove($target as item()*, $position as xs:integer) as item()*
    

    Summary: Returns a new sequence constructed from the value of $target
    with the item at the position
    specified by the value of $position
    removed

    ..5. Extract a subsequence from a sequence:

       subsequence($sourceSeq as item()*,
                   $startingLoc as xs:double,
                   $length as xs:double) **as item**()*
    

    Summary: Returns the contiguous sequence of items in the value of
    $sourceSeq beginning at the position
    indicated by the value of $startingLoc
    and continuing for the number of items
    indicated by the value of $length.

    And there are many more useful standard XPath 2.0 functions over sequences.

    Note: The only feature that the XPath 2.0 sequence doesn’t have is “nestedness”. A sequence is always “flat” and an item of a sequence cannot be a sequence itself. There are ways to simulate multi-level sequences — for example, an item can be a node and its children nodes can be regarded as a nested sequence.

    Update: Here is how these functions can be used conveniently to solve the OP’s updated question:

    <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns:my="my:my" >
    
     <xsl:template match="/">
      <xsl:sequence select="my:populateSequence((), 1, 10)"/>
     </xsl:template>
    
     <xsl:function name="my:populateSequence" as="xs:integer*">
      <xsl:param name="pSeq" as="xs:integer*"/>
      <xsl:param name="pStart" as="xs:integer"/>
      <xsl:param name="pEnd" as="xs:integer"/>
    
      <xsl:sequence select=
       "if($pStart gt $pEnd)
          then $pSeq
          else my:populateSequence(($pSeq, $pStart), $pStart+1, $pEnd)
       "/>
     </xsl:function>
    </xsl:stylesheet>
    

    When this XSLT 2.0 transformation is applied on any XML document (not used), the wanted result is produced:

    1 2 3 4 5 6 7 8 9 10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know how to do such thing. e.g. I have something
I would like to know if it's posible to have the horizontal scrollbar that
I would like to know if it is possible to have subquery in a
I would like to know if after calling functions the data I have in
I would like to know if there is a way in Android to have
I would like to know what solution I can use in order to have
I would like to know why designers of the URI standard chose to have
I would like to know what generic requirements are there to have Eclipse headless
I would like to know how can we validate the Credit Card. We have
I have 4 files and would like to know elements which are non overlapping

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.