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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:16:54+00:00 2026-05-14T14:16:54+00:00

In the below XSL every time the xsl:when gets satisfied I want to append

  • 0

In the below XSL every time the xsl:when gets satisfied I want to append as many <a> and </a> tags. But the data that needs to be populated inside the tags should be only once. I have shown the expected output at the end.

<xsl:param name="insert-file" as="document-node()" />
<xsl:template match="*">
<xsl:variable name="input">My text</xsl:variable> 
<xsl:variable name="Myxml" as="element()*"> 
    <xsl:call-template name="populateTag"> 
            <xsl:with-param name="nodeValue" select="$input"/> 
    </xsl:call-template> 
</xsl:variable>
<xsl:copy-of select="$Myxml"></xsl:copy-of>
</xsl:template>

<xsl:template name="populateTag"> 
    <xsl:param name="nodeValue"/> 
    <xsl:for-each select="$insert-file/insert-data/data">
        <xsl:choose> 
            <xsl:when test="@index = 1">
                <a><xsl:value-of select="$nodeValue"></xsl:value-of></a> 
            </xsl:when>             
        </xsl:choose> 
    </xsl:for-each> 
</xsl:template>     

Current output:

<?xml version="1.0" encoding="UTF-8"?>
<a>My text</a>
<a>My text</a>
<a>My text</a>
<a>My text</a>

I want the template “populateTag” to return me the xml in the below format. How do i modify the template “populateTag” to achive the same.

Expected output from template “populateTag”:
<?xml version="1.0" encoding="UTF-8"?>
<a><a><a><a>My text</a></a></a></a>

Please give your ideas.

  • 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-14T14:16:54+00:00Added an answer on May 14, 2026 at 2:16 pm

    For that to happen, you need some kind of recursion (to nest the a-elements).

    Without trying, because I don’t have a sample XML document:

    <xsl:param name="insert-file" as="document-node()" />
    <xsl:template match="*">
    <xsl:variable name="input">My text</xsl:variable> 
    <xsl:variable name="Myxml" as="element()*"> 
        <xsl:call-template name="populateTag"> 
                <xsl:with-param name="nodeValue" select="$input"/> 
                <xsl:with-param name="position" select="1"/> 
        </xsl:call-template> 
    </xsl:variable>
    <xsl:copy-of select="$Myxml"></xsl:copy-of>
    </xsl:template>
    
    <xsl:template name="populateTag"> 
        <xsl:param name="nodeValue"/> 
        <xsl:param name="position"/> 
        <xsl:variable name="total" select="count($insert-file/insert-data/data[@index = 1])" />
        <xsl:for-each select="$insert-file/insert-data/data[@index = 1]">
          <xsl:if test="position() = $position" >
              <xsl:choose> 
                  <xsl:when test="position() = $total">
                      <a><xsl:value-of select="$nodeValue"></xsl:value-of></a>
                  </xsl:when>             
                  <xsl:otherwise>
                    <a>    
                          <xsl:call-template name="populateTag"> 
                                  <xsl:with-param name="nodeValue" select="$input"/> 
                                  <xsl:with-param name="position" select="$position+1"/> 
                          </xsl:call-template> 
                    </a>
                  </xsl:otherwise>
              </xsl:choose> 
            </xsl:if>
        </xsl:for-each> 
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a xml that looks like below <xsl:template match=//xml> <xsl:for-each select=//z:row> <ul class
I want to output single quote around $ID variable in the below xsl:value-of xsl
What is the difference between using as=element(data)+ and as=element(data) in xsl:variable. The below XSL
I have an XSL template that is selected for execution (below). What I would
How to modify the below xsl to process parameters whose value is tags. Instead
here is my below xml under that table due based on CTD_CTD_PKG_ID(some time under
I'd like to optimize the XSL transform below. I've included sample input data and
I am creating an xsl file. I want to print below code as output
I have an XSLT like below, and want to use apply-templates inside the xsl:for-each
I am not that bright in XSL. I have an XML as below: <?xml

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.