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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:27:31+00:00 2026-06-17T09:27:31+00:00

With the following XML : <Sections><Section Type=Type1 Text=blabla1><Section Type=Type2 Text=blabla2/> </Section></Sections> I want to

  • 0

With the following XML :

<Sections><Section Type="Type1" Text="blabla1"><Section Type="Type2" Text="blabla2"/>  </Section></Sections>

I want to produce the following output :

<Sections><Type1 Text="blabla1"><Type2 Text="blabla2"/></Type1></Sections>

I’m playing with XSLT since many hours, I cant even figure out something to start with… There are many good example on XLST transformation but I’m still missing something about recursivity and using the Type attribute to create my node. How to transform any section node in the document to its corresponing type attribute?

Any tutorial that do something similar , xslt resources or anything to start with whould be great

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-06-17T09:27:32+00:00Added an answer on June 17, 2026 at 9:27 am

    How’s this (as requested in comments, modified to convert in both directions):

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" indent="yes"/>
    
      <xsl:template match="@* | node()">
        <xsl:copy>
          <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
      </xsl:template>
    
      <!-- Prevent Type attributes from being copied to the output-->
      <xsl:template match="@Type" />
    
      <!-- Convert <Section Type="Nnn" ... /> into <Nnn ... /> -->
      <xsl:template match="Section">
        <xsl:element name="{@Type}">
          <xsl:apply-templates select="@* | node()"/>
        </xsl:element>
      </xsl:template>
    
      <!-- Convert <Nnn .... /> into <Section Type="Nnn" ... /> -->
      <xsl:template match="Sections//*[not(self::Section)]">
        <Section Type="{name()}">
          <xsl:apply-templates select="@* | node()" />
        </Section>
      </xsl:template>
    
    </xsl:stylesheet>
    

    Output when run on your first example:

    <Sections>
      <Type1 Text="blabla1">
        <Type2 Text="blabla2" />
      </Type1>
    </Sections>
    

    Output when run on your second example:

    <Sections>
      <Section Type="Type1" Text="blabla1">
        <Section Type="Type2" Text="blabla2" />
      </Section>
    </Sections>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following input XML: <root age=1> <description>some text</description> <section> <item name=a> <uuid>1</uuid>
I have the following XML file: <Section Id=1 Type=page Caption=Message Details> <Containers> <Form Id=General
I have the following structure to XML file: <INSTANCE> <Sections> <Section> <Forms> <Form> <Control
I have the following XML: <root> <section> <item name=a> <uuid>1</uuid> </item> </section> <section> <item
I have an XML document with a section similar to the following: <release_list> <release>
I have defined a config section in my app.config in the following way: <?xml
I have the following code var section = new CustomConfigurationSection(); section.SectionInformation.Type = System.Configuration.NameValueFileSectionHandler; section.SectionInformation.SetRawXml(sectionXml);
Given the following XML section from a large xml file: <item id=C3DD6846593 > <name
Given the following XML file: <?xml version=1.0 encoding=UTF-8?> <doc> <head> <title>Introduction</title> <section>section</section> <channel>testing/test</channel> </head>
select * from tablename where CONVERT(xml, Sections).value('(/sections/section/@value)[1]', 'varchar(1)') = 'f' will properly retrieve a

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.