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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:14:25+00:00 2026-05-17T22:14:25+00:00

Suppose i have a template foo which can output something given a parameter. Now

  • 0

Suppose i have a template foo which can output something given a parameter. Now I want to use that output as a parameter to my other template, loop so I can loop the output a certain number of times. I have tried something along the way of

    <xsl:call-template name="loop">
        <xsl:with-param name="times" select="someParam"/>
        <xsl:with-param name="output">
            <xsl:call-template name="foo">
                <xsl:with-param name="type" select="something"/>
            </xsl:call-template>
        </xsl:with-param>
    </xsl:call-template>

In other words, output should now contain the output from the call to foo. Both loop and foo work fine independantely but it seems like I can’t nest them this way. How should I accomplish this? Thanks in advance.

  • 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-17T22:14:26+00:00Added an answer on May 17, 2026 at 10:14 pm

    The problem is in the code you haven’t shown to us. This is a correct way to chain/pipe templates, although I would not recommend it (see at the end of this answer),

    This transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output method="text"/>
    
     <xsl:template match="/">
        <xsl:call-template name="loop">
            <xsl:with-param name="times" select="3"/>
            <xsl:with-param name="output">
                <xsl:call-template name="foo">
                    <xsl:with-param name="pN" select="5"/>
                </xsl:call-template>
            </xsl:with-param>
        </xsl:call-template>
     </xsl:template>
    
     <xsl:template name="loop">
      <xsl:param name="times" select="1"/>
      <xsl:param name="output" select="2"/>
    
      <xsl:choose>
          <xsl:when test="not($times > 0)">
           <xsl:value-of select="$output"/>
          </xsl:when>
          <xsl:otherwise>
           <xsl:call-template name="loop">
            <xsl:with-param name="times" select="$times -1"/>
            <xsl:with-param name="output" select="2*$output"/>
           </xsl:call-template>
          </xsl:otherwise>
      </xsl:choose>
     </xsl:template>
    
     <xsl:template name="foo">
      <xsl:param name="pN" select="1"/>
    
      <xsl:value-of select="2*$pN"/>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on any XML (not used), produces the wanted, correct result:

    80
    

    Stylistic recommendation:

    Try to avoid chaining templates in this way as this results in unreadable and unmaintainable code.

    It is much better to obtain the intermediate results into (properly named) variables. Not only is the code more readable and maintainable this way, but any intermediate result can be re-used multiple times without the need to re-evaluate it.

    Here is the same transformation but factored to meet the recommended stylistic requirements:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output method="text"/>
    
     <xsl:template match="/">
       <xsl:variable name="vTwice">
        <xsl:call-template name="twice">
          <xsl:with-param name="pN" select="5"/>
        </xsl:call-template>
       </xsl:variable>
    
        <xsl:call-template name="loop">
            <xsl:with-param name="pTtimes" select="3"/>
            <xsl:with-param name="pN" select="$vTwice"/>
        </xsl:call-template>
     </xsl:template>
    
     <xsl:template name="loop">
      <xsl:param name="pTtimes" select="1"/>
      <xsl:param name="pN" select="2"/>
    
      <xsl:choose>
          <xsl:when test="not($pTtimes > 0)">
           <xsl:value-of select="$pN"/>
          </xsl:when>
          <xsl:otherwise>
           <xsl:call-template name="loop">
            <xsl:with-param name="pTtimes" select="$pTtimes -1"/>
            <xsl:with-param name="pN" select="2*$pN"/>
           </xsl:call-template>
          </xsl:otherwise>
      </xsl:choose>
     </xsl:template>
    
     <xsl:template name="twice">
      <xsl:param name="pN" select="1"/>
    
      <xsl:value-of select="2*$pN"/>
     </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a template which takes 3 template parameter. I want the third
Suppose I have arbitrary template method, which could receive parameters by value and by
Suppose I have a button nested in the Template of a ListBoxItem , can
To illustrate my question more clearly, let's suppose I have a include.html template with
I have an app that has a ListBox of ListBoxes. I would like to
This one is sort of twisting my noodle. I have something resembling this (in
Suppose I compile a source file file which contains this piece of code, struct
I am building an AJAX deep-linked site. I want PHP to load all the
Let me say we have a simple programming task. But for the sake of

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.