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

  • Home
  • SEARCH
  • 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 3288262
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:35:15+00:00 2026-05-17T20:35:15+00:00

I need to rearrange all the the child elements of an XML Document underneath

  • 0

I need to rearrange all the the child elements of an XML Document underneath the first Parent (and discard all other parent info)

In the example below, I need all 4 child elements under Parent[ParentField=1] and discard Parent[ParentField=X]

<xml>
    <Parent>
        <ParentField>1</ParentField>
        <Children>
            <Child>
                <id>1</id>
            </Child>
            <Child>
                <id>2</id>
            </Child>
        </Children>
    </Parent>
    <Parent>
        <ParentField>X</ParentField>
        <Children>
            <Child>
                <id>3</id>
            </Child>
            <Child>
                <id>4</id>
            </Child>
        </Children>
    </Parent>
</xml>

Resulting in XML like so:

<xml>
    <Parent>
        <ParentField>1</ParentField>
        <Children>
            <Child>
                <id>1</id>
            </Child>
            <Child>
                <id>2</id>
            </Child>
            <Child>
                <id>3</id>
            </Child>
            <Child>
                <id>4</id>
            </Child>
        </Children>
    </Parent>
</xml>
  • 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-05-17T20:35:16+00:00Added an answer on May 17, 2026 at 8:35 pm

    This stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:param name="pParentField" select="1"/>
        <xsl:template match="node()|@*" name="identity">
            <xsl:copy>
                <xsl:apply-templates select="node()|@*"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="Parent">
            <xsl:if test="ParentField = $pParentField">
                <xsl:call-template name="identity"/>
            </xsl:if>
        </xsl:template>
        <xsl:template match="Children">
            <xsl:copy>
                <xsl:apply-templates select="/xml/Parent/Children/Child"/>
            </xsl:copy>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <xml>
        <Parent>
            <ParentField>1</ParentField>
            <Children>
                <Child>
                    <id>1</id>
                </Child>
                <Child>
                    <id>2</id>
                </Child>
                <Child>
                    <id>3</id>
                </Child>
                <Child>
                    <id>4</id>
                </Child>
            </Children>
        </Parent>
    </xml>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need to set some attributes of button. For example Checked. I guess it is
Need help getting Ember-Data working with Zend Rest. At first, I'm familiar with Zend
I desperately need to sort an array: heres the situation, I need to rearrange
Say I have an XML document (represented as text, a W3C DOM, whatever), and
I need to rearrange some content in various directories but it's a bit of
I have an XML file and I am loading it in Xmldocument. This document
i try to rearrange my sorce files eg: remove all css styles from aspx
I've got a tree structure that I need to rearrange (drag and drop) and
I need to swap characters of a string (which is mmddyyyy format) and rearrange
I have a CSV file that i need to rearrange and renecode. I'd like

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.