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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:44:50+00:00 2026-06-05T05:44:50+00:00

i need to remove xmi node if there is only 1 child. If i

  • 0

i need to remove xmi node if there is only 1 child. If i remove xmi node i need to copy attributes to new root node.

<xmi:XMI attribute="2" xmlns:xmi="http://www.omg.org/spec/XMI/20110701" xmlns:a="A">
<namespace:node attribute2="att">
...
</namespace:node>
</xmi:XMI>

i need to get

<namespace:node attribute2="att" attribute="2" xmlns:xmi="http://www.omg.org/spec/XMI/20110701" xmlns:a="A">
...
</namespace:node>

but if there is

<xmi:XMI attribute="2" xmlns:xmi="http://www.omg.org/spec/XMI/20110701" xmlns:a="A">
<namespace:node attribute2="att">
...
</namespace:node>
<otherNode/>
</xmi:XMI>

no changes must be done.

Any help appreciated.

  • 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-05T05:44:52+00:00Added an answer on June 5, 2026 at 5:44 am

    This XSLT 1.0 transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xmi="http://www.omg.org/spec/XMI/20110701">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="xmi:XMI[not(*[2])]">
      <xsl:apply-templates/>
     </xsl:template>
    
     <xsl:template match="xmi:XMI[not(*[2])]/*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@* | ../@*"/>
         </xsl:copy>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the following XML document :

    <xmi:XMI attribute="2"
               xmlns:xmi="http://www.omg.org/spec/XMI/20110701"
               xmlns:a="A" >
            <namespace:node attribute2="att" xmlns:namespace="some:namespace">
              ...
            </namespace:node>
            <otherNode/>
    </xmi:XMI>
    

    produces the wanted, correct result (no changes):

    <xmi:XMI xmlns:xmi="http://www.omg.org/spec/XMI/20110701" xmlns:a="A" attribute="2">
       <namespace:node xmlns:namespace="some:namespace" attribute2="att">
              ...
            </namespace:node>
       <otherNode/>
    </xmi:XMI>
    

    When applied on this XML document:

    <xmi:XMI attribute="2"
               xmlns:xmi="http://www.omg.org/spec/XMI/20110701"
               xmlns:a="A" >
            <namespace:node attribute2="att" xmlns:namespace="some:namespace">
              ...
            </namespace:node>
    </xmi:XMI>
    

    again the wanted, correct result is produced (the xmi:XMI element is “deleted” and its attributes are copied to its only child):

    <namespace:node xmlns:namespace="some:namespace"    
     xmlns:xmi="http://www.omg.org/spec/XMI/20110701" xmlns:a="A" 
     attribute="2" attribute2="att">
              ...
    </namespace:node>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to remove the tags for the numbers only.. as there are some
I need to remove tags going after #first and only in #container . How
I need to remove an image with the give src img_src = http://domain/img.jpg @doc.xpath(//img[@src='#{img_src}'])[0].remove
I need to remove attribute from XML document by this attribute's XPath. Everything should
I need to remove particular child nodes from their parent in treeview control. For
I need to remove commas within a String only when enclosed by quotes. example:
I need to remove all attributes set on certain elements (using vanilla JS or
I need to remove the following format from the end of a string in
I need to remove whitespaces after the word in the string. Can this be
I need to remove all entries in a dictionary accordingly to a specified lower

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.