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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:32:50+00:00 2026-05-15T05:32:50+00:00

Essentially, I have XML structured like this: <A> <B> <1>data</1> <2>data</2> <C> <1>data</1> <2>data</2>

  • 0

Essentially, I have XML structured like this:

<A>
 <B>
  <1>data</1>
  <2>data</2>
  <C>
   <1>data</1>
   <2>data</2>
   <B>
    <1>data</1>
    <2>data</2>
    <C>
     <B>
      <1>data</1>
      <2>data</2>
     </B>
    </C>
   </B>
   <B>
    <1>data</1>
    <2>data</2>
   </B>
  </C>
 </B>
</A>

I am trying to get the output to look like this:

<A>
<B 1="data" 2="data">
    <C 1="data" 2="data">
        <B 1="data" 2="data">
            <C>
                <B 1="data" 2="data" >
                </B>
            </C>
        </B>
        <B 1="data" 2="data" >
        </B>
    </C>
</B>
</A>

I have figured out how to put everything as attributes and start looping through the elements. The issue I am facing is that when trying to get below the first C, nothing happens. Here is my code:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
    <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/">
    <MenuDataResult>
      <B>
        <xsl:apply-templates />
      </B>
    </MenuDataResult>
  </xsl:template>

  <xsl:template match="B">
        <xsl:for-each select="B">
          <B ItemID="{B/ItemID/text()}" ItemType="{ItemType/text()}" ItemSubType="{ItemSubType/text()}"
                  ItemTitle="{ItemTitle/text()}" ItemImage="{ItemImage/text()}" ItemImageOverride="{ItemImageOverride/text()}"
                ItemLink="{ItemLink/text()}" ItemTarget="{ItemTarget/text()}>">
            <xsl:for-each select="C">
              <xsl:apply-templates select="C"/>
            </xsl:for-each>
          </B>
        </xsl:for-each>
  </xsl:template>

  <xsl:template match="C">
    <C ID="{ID/text()}" Title="{Title/text()}" Template="{Template/text()}"
          Type="{Type/text()}" Link="{Link/text()}" ParentID="{ParentID/text()}"
          AncestorID="{AncestorID/text()}" FolderID="{FolderID/text()}" Description="{Description/text()}"
          Image="{Image/text()}" ImageOverride="{ImageOverride/text()}">
      <xsl:for-each select="B">
        <xsl:apply-templates select=".//B"/>
      </xsl:for-each>
    </C>
  </xsl:template>

</xsl:stylesheet>
  • 1 1 Answer
  • 2 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-05-15T05:32:51+00:00Added an answer on May 15, 2026 at 5:32 am

    In the spirit of XSLT: this transformation:

    <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="a1|a2">
      <xsl:attribute name="{name()}">
        <xsl:value-of select="."/>
      </xsl:attribute>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the corrected XML document from Alejandro’s example:

    <A>
     <B>
      <a1>data</a1>
      <a2>data</a2>
      <C>
       <a1>data</a1>
       <a2>data</a2>
       <B>
        <a1>data</a1>
        <a2>data</a2>
        <C>
         <B>
          <a1>data</a1>
          <a2>data</a2>
         </B>
        </C>
       </B>
       <B>
        <a1>data</a1>
        <a2>data</a2>
       </B>
      </C>
     </B>
    </A>
    

    produces the desired, correct output:

    <A>
       <B a1="data" a2="data">
          <C a1="data" a2="data">
             <B a1="data" a2="data">
                <C>
                   <B a1="data" a2="data"/>
                </C>
             </B>
             <B a1="data" a2="data"/>
          </C>
       </B>
    </A>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that looks something like this: <product> <modelNumber>Data</modelNumber> <salePrice>Data</salePrice> </product>
You'll have to excuse me if I'm describing this incorrectly, but essentially I'm trying
I'm trying to build a Hibernate layer for a database schema I have essentially
First i was wondering if this is a good idea, essentially i have user
Essentially I would like to have a messages.properties files external to the jar files
I have an rss feed for my podcast and essentially what I am trying
If i have the following directory structure: Project1/bin/debug Project2/xml/file.xml I am trying to refer
I have some XML that stores column information and row data from a table
This is essentially very simple I've just been rather verbose about it. My data
I essentially have an xml file in which one attribute is a link which

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.