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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:34:02+00:00 2026-06-05T17:34:02+00:00

I have several xml files that are formated this way: <ROOT> <OBJECT> <identity> <id>123</id>

  • 0

I have several xml files that are formated this way:

<ROOT>
  <OBJECT>
    <identity>
        <id>123</id>
    </identity>     
    <child2 attr = "aa">32</child2>
    <child3>
        <childOfChild3 att1="aaa" att2="bbb" att3="CCC">LN</childOfChild3>
    </child3>
    <child4>
        <child5>
            <child6>3ddf</child6>
            <child7>
                <childOfChild7 att31="RR">1231</childOfChild7>
            </child7>
        </child5>
    </child4>
  </OBJECT>
  <OBJECT>
    <identity>
        <id>124</id>
    </identity>     
    <child2 attr = "bb">212</child2>
    <child3>
        <childOfChild3 att1="ee" att2="ccc" att3="EREA">OP</childOfChild3>
    </child3>
    <child4>
        <child5>
            <child6>213r</child6>
            <child7>
                <childOfChild7 att31="EE">1233</childOfChild7>
            </child7>
        </child5>
    </child4>
  </OBJECT>
</ROOT>

How can i format it this way?:

<ROOT>
    <OBJECT>    
        <id>123</id>
        <child2>32</child2> 
        <attr>aa</attr>
        <child3></child3>
        <childOfChild3>LN</childOfChild3>
        <att1>aaa</att1>
        <att2>bbb</att2>
        <att3>CCC</att3>
        <child4></child4>
        <child5></child5>
        <child6>3ddf</child6>
        <child7></child7>
        <childOfChild7>1231</childOfChild7>
        <att31>RR</att31>
    </OBJECT>
        <OBJECT>    
        <id>124</id>
        <child2>212</child2>    
        <attr>bb</attr>
        <child3></child3>
        <childOfChild3>LN</childOfChild3>
        <att1>ee</att1>
        <att2>ccc</att2>
        <att3>EREA</att3>
        <child4></child4>
        <child5></child5>
        <child6>213r</child6>
        <child7></child7>
        <childOfChild7>1233</childOfChild7>
        <att31>EE</att31>
    </OBJECT>   
</ROOT>

I know some C# so maybe a parser there? or some generic xslt?
The xml files are some data received from a client, so i can’t control the way they are sending it to me.

L.E. Basically when i am trying to test this data in excel (for example i want to make sure that the attribute of childOfChild7 corresponds to the correct identity id) i am getting a lot of blank spaces. If i am importing in access to get only the data i want out, i have to do a thousands subqueries to get them all in a nice table. Basically i just want to see for one Object all its data (one object – One row) and then just delete/hide the columns i don’t need.

  • 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-05T17:34:03+00:00Added an answer on June 5, 2026 at 5:34 pm

    Here is a pure XSLT 1.0 solution:

    <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="*"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="OBJECT//*[not(self::identity) and text()]">
      <xsl:copy>
       <xsl:apply-templates select="text()"/>
      </xsl:copy>
      <xsl:apply-templates select="@* | node()[not(self::text())]"/>
     </xsl:template>
    
     <xsl:template match="OBJECT//*[not(self::identity) and (not(text()))]">
      <xsl:copy/>
      <xsl:apply-templates select="@*"/>
      <xsl:apply-templates select="node()"/>
     </xsl:template>
    
     <xsl:template match="@*">
      <xsl:element name="{name()}">
       <xsl:value-of select="."/>
      </xsl:element>
     </xsl:template>
    
     <xsl:template match="identity">
      <xsl:apply-templates/>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the provided XML document:

    <ROOT>
        <OBJECT>
            <identity>
                <id>123</id>
            </identity>
            <child2 attr = "aa">32</child2>
            <child3>
                <childOfChild3 att1="aaa" att2="bbb" att3="CCC">LN</childOfChild3>
            </child3>
            <child4>
                <child5>
                    <child6>3ddf</child6>
                    <child7>
                        <childOfChild7 att31="RR">1231</childOfChild7>
                    </child7>
                </child5>
            </child4>
        </OBJECT>
        <OBJECT>
            <identity>
                <id>124</id>
            </identity>
            <child2 attr = "bb">212</child2>
            <child3>
                <childOfChild3 att1="ee" att2="ccc" att3="EREA">OP</childOfChild3>
            </child3>
            <child4>
                <child5>
                    <child6>213r</child6>
                    <child7>
                        <childOfChild7 att31="EE">1233</childOfChild7>
                    </child7>
                </child5>
            </child4>
        </OBJECT>
    </ROOT>
    

    the wanted, correct result is produced:

    <ROOT>
       <OBJECT>
          <id>123</id>
          <child2>32</child2>
          <attr>aa</attr>
          <child3/>
          <childOfChild3>LN</childOfChild3>
          <att1>aaa</att1>
          <att2>bbb</att2>
          <att3>CCC</att3>
          <child4/>
          <child5/>
          <child6>3ddf</child6>
          <child7/>
          <childOfChild7>1231</childOfChild7>
          <att31>RR</att31>
       </OBJECT>
       <OBJECT>
          <id>124</id>
          <child2>212</child2>
          <attr>bb</attr>
          <child3/>
          <childOfChild3>OP</childOfChild3>
          <att1>ee</att1>
          <att2>ccc</att2>
          <att3>EREA</att3>
          <child4/>
          <child5/>
          <child6>213r</child6>
          <child7/>
          <childOfChild7>1233</childOfChild7>
          <att31>EE</att31>
       </OBJECT>
    </ROOT>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several different XSLT files that all work on the same original XML
hey guys, we have a loop that: 1.Loops over several thousand xml files. Altogether
I have several files (they are XML but that's not important) that need to
I have several XML files that I wish to read attributes from. My main
I have several fairly large XML files that represent data exported from a system
I am working on a system that will have several hundred thousand XML files,
i have a asp.net mvc application which uploads several xml files that are used
I have parametrized junit test that reads from several XML input files. In the
I noticed myself constantly typing: someVar = getResources().getString(R.string.someString); I have several XML files that
I have several existing XML schema files with a defined data model. I would

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.