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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:14:33+00:00 2026-06-01T07:14:33+00:00

I am trying to transform an XML file into an updated version. I have

  • 0

I am trying to transform an XML file into an updated version.

I have the following Source XML

<?xml version="1.0" encoding="utf-8" ?>
<config>
  <section name="abc">
    <key name="key1">My Key One</key>
  </section>
  <section name="def">
    <key name="key2">My Key Two</key>
  </section>
</config>

The transformation is to look like this… however, the target actually may already look like this, so I do not want section xyz added if already exists:

<?xml version="1.0" encoding="utf-8" ?>
<config>
  <section name="abc">
    <key name="key1">My Key One</key>
  </section>
  <section name="def">
    <key name="key2">My Key Two</key>
  </section>
  <section name="xyz">
    <key name="key3">My Key Three</key>
  </section>
</config>

XSLT currently looks like this:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="config">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="@*|text()|comment()|processing-instruction()">
<xsl:copy-of select="."/>
</xsl:template>

<xsl:template match="config/section">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="config/section/key">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

This appears to replicate what exists. How do I get it to add my missing element if it is in fact missing?

  • 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-01T07:14:34+00:00Added an answer on June 1, 2026 at 7:14 am

    Try something like this:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output indent="yes"/>
      <xsl:strip-space elements="*"/>
    
      <xsl:template match="node()|@*">
        <xsl:copy>
          <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
      </xsl:template>
    
      <xsl:template match="config">
        <xsl:copy>
          <xsl:apply-templates select="node()|@*"/>
          <xsl:if test="not(section/@name='xyz')">
            <section name="xyz">
              <key name="key3">My Key Three</key>
            </section>
          </xsl:if>
        </xsl:copy>    
      </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to have a script automatically transform an xml file into several html
i have the following xslt sheet: <?xml version=1.0 encoding=UTF-8 ?> <xsl:stylesheet xmlns:xsl=http://www.w3.org/1999/XSL/Transform version=1.0> <xsl:variable
I'm trying to query an xml file using the following xslt: <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform
I have an XML file and I'm trying convert it into a (table( HTML
I have the following structure to XML file: <INSTANCE> <Sections> <Section> <Forms> <Form> <Control
I'm trying to use an XSL file to transform an XML file into an
I am trying to transform an xml file with xsl stylesheet into html. this
I am trying to develop an XSLT stylesheet which will transform an xml into
I have: NSString *promise = @thereAreOtherWorldsThanThese; which I'm trying to transform into the string:
I need to transform an XML file to another XML file, where the source

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.