0
votes

I want to copy nodes from parent to the child. I am not really sure how this can be acheived.

My source xml

<Root1>
    <Family1>
      <Childrens>
        <Child>
          <ChildFirstName>Robin1</ChildFirstName>
          <ChildLastName>Jackman1</ChildLastName>
          <Address>
            <Street1>Street1</Street1>
            <State>State</State>
            <Country>Country</Country>
          </Address>
          <Activities>
            <Sports>
              <Cricket>
                <ParticipentNames>

                </ParticipentNames>
              </Cricket>
            </Sports>
          </Activities>
        </Child>
        <Child>
          <ChildFirstName>Robin2</ChildFirstName>
          <ChildLastName>Jackman2</ChildLastName>
          <Address>
            <Street1>Street1</Street1>
            <State>State</State>
            <Country>Country</Country>
          </Address>
          <Activities>
            <Sports>
              <Cricket>
                <ParticipentNames>

                </ParticipentNames>
              </Cricket>
            </Sports>
          </Activities>
        </Child>
        <Child>
          <ChildFirstName>Robin3</ChildFirstName>
          <ChildLastName>Jackman3</ChildLastName>
          <Address>
            <Street1>Street1</Street1>
            <State>State</State>
            <Country>Country</Country>
          </Address>
          <Activities>
            <Sports>
              <Cricket>
                <ParticipentNames>

                </ParticipentNames>
              </Cricket>
            </Sports>
          </Activities>
        </Child>
      </Childrens>
    </Family1>
  </Root1>

I would like to get the output as

<Root1>
    <Family1>
      <Childrens>
        <Child>
          <ChildFirstName>Robin1</ChildFirstName>
          <ChildLastName>Jackman1</ChildLastName>
          <Address>
            <Street1>Street1</Street1>
            <State>State</State>
            <Country>Country</Country>
          </Address>
          <Activities>
            <Sports>
              <Cricket>
                <ParticipentNames>
                  <ChildFirstName>Robin1</ChildFirstName>
                  <ChildLastName>Jackman1</ChildLastName>
                  <Address>
                    <Street1>Street1</Street1>
                    <State>State</State>
                    <Country>Country</Country>
                  </Address>
                </ParticipentNames>
              </Cricket>
            </Sports>
          </Activities>
        </Child>
        <Child>
          <ChildFirstName>Robin2</ChildFirstName>
          <ChildLastName>Jackman2</ChildLastName>
          <Address>
            <Street1>Street1</Street1>
            <State>State</State>
            <Country>Country</Country>
          </Address>
          <Activities>
            <Sports>
              <Cricket>
                <ParticipentNames>
                  <ChildFirstName>Robin2</ChildFirstName>
                  <ChildLastName>Jackman2</ChildLastName>
                  <Address>
                    <Street1>Street1</Street1>
                    <State>State</State>
                    <Country>Country</Country>
                  </Address>
                </ParticipentNames>
              </Cricket>
            </Sports>
          </Activities>
        </Child>
        <Child>
          <ChildFirstName>Robin3</ChildFirstName>
          <ChildLastName>Jackman3</ChildLastName>
          <Address>
            <Street1>Street1</Street1>
            <State>State</State>
            <Country>Country</Country>
          </Address>
          <Activities>
            <Sports>
              <Cricket>
                <ParticipentNames>
                  <ChildFirstName>Robin3</ChildFirstName>
                  <ChildLastName>Jackman3</ChildLastName>
                  <Address>
                    <Street1>Street1</Street1>
                    <State>State</State>
                    <Country>Country</Country>
                  </Address>
                </ParticipentNames>
              </Cricket>
            </Sports>
          </Activities>
        </Child>
      </Childrens>
    </Family1>
  </Root1>

I want the solution in XSLT 1.0.

I want to copy these nodes to child nodes

                  <ChildFirstName>Robin3</ChildFirstName>
                  <ChildLastName>Jackman3</ChildLastName>
                  <Address>
                    <Street1>Street1</Street1>
                    <State>State</State>
                    <Country>Country</Country>
                  </Address>

Thanks.

1
Reverse XPath is not recommended!!!!InfantPro'Aravind'
Your source XML and desired output are very big and you haven't explained exactly which nodes from the source XML document should be copied exactly under which element. Also, your XSLT code references elements that aren't present in the currently-provided source XML document. Due to these facts, the question at present is confucing and subject to guessing. Please, edit the question and specify all necessary information precisely.Dimitre Novatchev

1 Answers

1
votes
<?xml version="1.0" encoding="utf-8"?>
<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>
  <xsl:template match="/OrderItem/ProductionInformation/GSItem">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
      <xsl:for-each select="/OrderItem">
        <xsl:apply-templates select="@*|node()[name()!='ProductionInformation']"/>
      </xsl:for-each>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>