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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:34:16+00:00 2026-06-04T22:34:16+00:00

I have a XML where I only want to modify a specific section, and

  • 0

I have a XML where I only want to modify a specific section, and leave the rest intact, how can this be done? i.e I only want to modify the node AA2

<root>
  <parentHeader>
  </parentHeader>
  <body>
    <ChildAA>
      <AA1>
        <foo>bar</foo>
        <foo>bar2</foo>    
      </AA1>
      <AA2>
        <foo>bar</foo>
        <foo>bar2</foo>    
      </AA2>
     </ChildAA>
     <ChildBB>
      <BB1>
       <foo>bar</foo>
       <foo>bar2</foo>
      </BB1> 
      <BB2>
       <foo>bar</foo>
       <foo>bar2</foo>
      </BB2>   
     </ChildBB>
   </body>
</root>

I have the following XSLT which only returns the modified section. How can I include everything else?

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>

      <!-- Whenever you match any node or any attribute -->
      <xsl:template match="/*"> 
           <xsl:apply-templates/>  
      </xsl:template>


    <xsl:template match="AA2">
       <RenamedAA2>    
         <xsl:copy-of select="."/>
      </RenamedAA2>
    </xsl:template>    
    <xsl:template match="text()"/>

</xsl:stylesheet>

I am looking for something like this as result

<root>
  <parentHeader>
  </parentHeader>
  <body>
    <ChildAA>
      <AA1>
        <foo>bar</foo>
        <foo>bar2</foo>    
      </AA1>
     <RenamedAA2>
        <foo>bar</foo>
      </RenamedAA2>
      <RenamedAA2>
        <foo>bar2</foo>    
      </RenamedAA2>
     </ChildAA>
     <ChildBB>
      <BB1>
       <foo>bar</foo>
       <foo>bar2</foo>
      </BB1> 
      <BB2>
       <foo>bar</foo>
       <foo>bar2</foo>
      </BB2>   
     </ChildBB>
   </body>
</root>
  • 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-06-04T22:34:18+00:00Added an answer on June 4, 2026 at 10:34 pm

    What you want is the identity transform.

    Your template that has the comment Whenever you match any node or any attribute isn’t doing what you think. It’s only matching the root element.

    Also, you’re stripping all text() nodes with that last template.

    Here’s an example of what you should do:

    XSLT 1.0

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output indent="yes"/>
        <xsl:strip-space elements="*"/>
    
        <!--Identity Transform.-->
        <xsl:template match="node()|@*">
            <xsl:copy>
                <xsl:apply-templates select="node()|@*"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="AA2/foo">
            <RenamedAA2>
                <xsl:copy>
                    <xsl:apply-templates select="node()|@*"/>
                </xsl:copy>
            </RenamedAA2>
        </xsl:template>
    
        <xsl:template match="AA2">
            <xsl:apply-templates/>
        </xsl:template>
    
    </xsl:stylesheet>
    

    XML Output

    <root>
       <parentHeader/>
       <body>
          <ChildAA>
             <AA1>
                <foo>bar</foo>
                <foo>bar2</foo>
             </AA1>
             <RenamedAA2>
                <foo>bar</foo>
             </RenamedAA2>
             <RenamedAA2>
                <foo>bar2</foo>
             </RenamedAA2>
          </ChildAA>
          <ChildBB>
             <BB1>
                <foo>bar</foo>
                <foo>bar2</foo>
             </BB1>
             <BB2>
                <foo>bar</foo>
                <foo>bar2</foo>
             </BB2>
          </ChildBB>
       </body>
    </root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a (hopefully) simple question: Can i modify a xml file located in
I have a xml like this and I want the attribute which is defined
This question is a continuation of Can XPath return only nodes that have a
I have seen XML Schema element with attributes containing only text but I have
I have a massive XML file. However, I'm only interested in a single small
I am pulling categories from an xml file. I only have 5 categories but
I'm using XmlWriterSettings to write Xml to file. I have elements with only attributes,
i have xml file that looks like this: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE pointList SYSTEM
I have xml listview. How I can change its height in activity? I know
I have XML like this: <article> <title>Article 1 title</title> <text>Lorem ipsum...</text> <image>http://example.com/img_01.jpg</image> </article> <article>

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.