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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:54:36+00:00 2026-06-07T00:54:36+00:00

I have the following XML :- <inventory> <item> <name_element> <!–some structure–> </name_element> <some_element1>val1</some_element1> <some_element2>val2</some_element2>

  • 0

I have the following XML :-

<inventory>
  <item>
    <name_element>
      <!--some structure-->
    </name_element>
    <some_element1>val1</some_element1>
    <some_element2>val2</some_element2>
    <!-- some more elements -->
  </item>
  <!-- lots of items -->
</inventory>

Now I want to convert this to :-

<inventory>
  <item some_element1="val1" some_element2="val2" ... >
    <name_element>
      <!-- as it is -->
    </name_element>
</inventory>

Basically I don’t know anything about the names/types of some_elements and any item could have any number of these elements. I do know that they are all simple types and convertible to attributes.

I’ve read Converting XML elements to XML attributes using XSLT which tells how I can convert all child elements to attributes but it’s not clear from that how I could exclude a specific ‘name_element’ from being converted to an attribute.

  • 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-07T00:54:38+00:00Added an answer on June 7, 2026 at 12:54 am
    <?xml version="1.0" encoding="UTF-8"?> 
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0">
        <xsl:output indent="yes" method="xml"/>
    
        <xsl:template match="@*|node()">
         <xsl:copy>
             <xsl:apply-templates select="@*|node()"/>
         </xsl:copy>
        </xsl:template>
    
        <xsl:template match="item">
            <xsl:copy>
                <!--apply templates for any attributes and convert 
                    elements(except for name_element) in order to create all 
                    attributes before creating child nodes for item element -->
                <xsl:apply-templates select="@* 
                                             | *[not(self::name_element)]"/>
                <!--apply templates to name_element and any comments or processing instructions -->
                <xsl:apply-templates select="name_element 
                                             | comment() 
                                             | processing-instruction()"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="item/*[not(self::name_element)]">
            <xsl:attribute name="{local-name()}">
                <xsl:value-of select="."/>
            </xsl:attribute>
        </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 have the following XML structure: <?xml version=1.0 ?> <course xml:lang=nl> <body> <item id=787900813228567
I have the following XML source structure: <turnovers> <turnover repid=1 amount=500 rate=0.1/> <turnover repid=5
I have the following XML example <?xml version=1.0?> <test> <items> <item>item 1</item> <item>item 2</item>
I have the following xml structure <clinic> <category> <employees> <medic> <medic_details> <medic_name /> <medic_address
I have the following xml sample: <items> <item> <item_id>1</item_id> <item_name>item 1</item_name> <group_id>1</group_id> <group_name>group 1</group_name>
I have the following XML document : <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE inventory SYSTEM books.dtd>
I have the following XML layout for an item that I put in my
I have following XML: <Library> <Item> <Field Name=Name>smooth</Field> <Field Name=File Type>mid</Field> <Field Name=File Size>60026</Field>
I have the following xml string: <report> <item id=4219 Co=6063 LastName=Doe FirstName=John/> <item id=2571
i have the following xml structure and want to add it to a treeview.

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.