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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:52:31+00:00 2026-05-16T05:52:31+00:00

I have the following xml and want to insert additional xml into it: <root>

  • 0

I have the following xml and want to insert additional xml into it:

<root>
    <steps>
        <step name="step1" type="process">
            <steps>
                <step name="substep1">
                </step>
            </steps>
        </step>
        <step name="step2" type="process">
            <steps>
                <step name="substep1">
                <!-- more substeps...-->
                </step>
            </steps>
        </step>
        <step name="step3" type="process">
            <steps>
                <step name="substep1">
                </step>
                <step name="substep2">
                </step>
                <!-- more substeps...-->
            </steps>
        </step>
        <!-- THE BELOW IS WHAT I WISH TO ADD... and it has to be here -->
        <step name="reference">
            <!-- These stuff have been hardcoded in my xsl so its fine -->
        </step>
        <!-- ends -->
    </steps>
    <references>
        <reference name="reference1">
        </reference>
        .
        .
        .
    </references>
</root>

As I’ve written in the xml sample, I wish to add an additional step element as the very last step within the outter most steps. I have the xml snippet already hardcoded in my xsl so all I needed to do is to find the best logic to move to that particular point of the xml tree so I can call the template and have that snipet added in.

What is the recommended/best approach to do this?

Thanks.

  • 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-16T05:52:32+00:00Added an answer on May 16, 2026 at 5:52 am

    This transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     exclude-result-prefixes="xsl">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:param name="pAddition">
       <step name="reference">
         <XXX/>
       </step>
     </xsl:param>
    
     <xsl:template match="node()|@*" name="identity">
      <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="/*/steps/step[position()=last()]">
      <xsl:call-template name="identity"/>
      <xsl:copy-of select="$pAddition"/>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on this XML document:

    <root>
        <steps>
            <step name="step1" type="process">
                <steps>
                    <step name="substep1">
                    </step>
                </steps>
            </step>
            <step name="step2" type="process">
                <steps>
                    <step name="substep1">
                    <!-- more substeps...-->
                    </step>
                </steps>
            </step>
            <step name="step3" type="process">
                <steps>
                    <step name="substep1">
                    </step>
                    <step name="substep2">
                    </step>
                    <!-- more substeps...-->
                </steps>
            </step>
        </steps>
        <references>
            <reference name="reference1">
            </reference>
            .
            .
            .
        </references>
    </root>
    

    produces the wanted, correct result:

    <root>
       <steps>
          <step name="step1" type="process">
             <steps>
                <step name="substep1"/>
             </steps>
          </step>
          <step name="step2" type="process">
             <steps>
                <step name="substep1"><!-- more substeps...--></step>
             </steps>
          </step>
          <step name="step3" type="process">
             <steps>
                <step name="substep1"/>
                <step name="substep2"/><!-- more substeps...-->
             </steps>
          </step>
          <step name="reference">
             <XXX/>
          </step>
       </steps>
       <references>
          <reference name="reference1"/>
            .
            .
            .
        </references>
    </root>
    

    Do note:

    1. **The identity rule is used to copy all nodes as is.

    2. The XML fragment to be inserted is specified (for convenience) as the body of a global xsl:param. In a realistic application it will be in a separate xml file and will be obtained using the xslt document() function.

    3. The template that matches the insertion point copies the matched node by calling the identity rule. then it copies the content of the xsl:param and thus the new conted is output exactly at the desired insertion point.

    • 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.