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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:20:27+00:00 2026-05-16T18:20:27+00:00

I have an xml <Root> <Parent> <Child1><Node1>AAA</Node1><Node2>BBB</Node2></Child1> <Child2><NodeX>XXX</NodeX><NodeY>YYY</NodeY></Child2> <Child1><Node1>EEE</Node1><Node2>FFF</Node2></Child1> <Child2><NodeX>GGG</NodeX><NodeY>HHH</NodeY></Child2> <OtherChild></OtherChild> </Parent> </Root> Child2

  • 0

I have an xml

 <Root>
  <Parent>
    <Child1><Node1>AAA</Node1><Node2>BBB</Node2></Child1>
    <Child2><NodeX>XXX</NodeX><NodeY>YYY</NodeY></Child2>
    <Child1><Node1>EEE</Node1><Node2>FFF</Node2></Child1>
    <Child2><NodeX>GGG</NodeX><NodeY>HHH</NodeY></Child2>
    <OtherChild></OtherChild>

  </Parent>
</Root>

Child2 always will be with child1. I need to know how I can loop through using xsl:foreach and create an XML output example. I may have other nodes like <OtherChild> but my concern
is only Child1 and Chid2 nodes

    <TransformedXML>
  <Child attributefromNode1="AAA" attributefromNode2="BBB" attributefromNodeX="XXX" attributeFromNodeY="YYY"/>
  <Child attributefromnode1="EEE" attributefromNode2="FFF" attributefromNodeX="GGG" attributeFromNodeY="HHH"/>
</TransformedXML>

My question is how do I loop in XSLT considering Child2 node will follow a Child1 always?

  • 1 1 Answer
  • 4 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-16T18:20:28+00:00Added an answer on May 16, 2026 at 6:20 pm

    I this something like this should do the trick:

      <xsl:stylesheet version="1.0"                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns="http://www.w3.org/TR/xhtml1/strict">
      <xsl:output
       method="xml"
       indent="yes" />
    
      <xsl:template match="/">
    <xsl:for-each select="Root/Parent/Child1">
    <Child>
      <xsl:attribute name="attributefromNode1">
        <xsl:value-of select="Node1" />
    
      </xsl:attribute>
      <xsl:attribute name="attributefromNode2" >
        <xsl:value-of select="Node2" />
    
      </xsl:attribute>
      <xsl:attribute name="attributefromNodeX">
        <xsl:value-of select="following-sibling::Child2/NodeX" />
    
      </xsl:attribute>
      <xsl:attribute name="attributefromNodeY">
        <xsl:value-of select="following-sibling::Child2/NodeY" />
    
      </xsl:attribute>
    
    
    
    </Child>   
        </xsl:for-each>
        </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 an xml <Root> <Parent> <Child1>A</Child1> <Child2>B</Child2> <Child1>X</Child1> <Child2>Y</Child2> </Parent> </Root> Child2 always
I have the folowing test.xml <root> <parent> <ID>1</ID> <child1>Value1</child1> <child2>value11</child2> <child3> <subchild>value111</subchild> </child3> </parent>
Consider the following test.xml <root> <parent> <ID>1</ID> <child1>Value1</child1> <child2>value11</child2> <child3> <grandchild> <greatgrandchild>value1111</greatgrandchild> </grandchild> </child3>
Suppose I have the following XML: <root> <parent> <name>Luiz</name> <son><name>Luiz</name</son> <daugther><name>Cristina</name></daughter> </parent> <parent> <name>Cristina</name>
Suppose I have an XML document stored as an Anti-XML Elem : val root
I have an XML document with a default namespace indicated at the root. Something
I have several xml files that are formated this way: <ROOT> <OBJECT> <identity> <id>123</id>
I have an xml that comes in two forms <root> <element1 req=mandatory/> <element2/> <element3/>
Hi I have an xml document like this <root> <cert id=1> </cert> <cert id=2>
I have an XML file that looks like <?xml version='1.0' encoding='UTF-8'?> <root> <node name=foo1

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.