change the order of the tags with xsl

Hi ,
i have the below xml,

<Doc>
    <Ins00>Insert00</Ins00>
    <Ins5>Insert5</Ins5>
    <Ins6>Insert6</Ins6>
    <Ins20>Insert20</Ins20>
    <Ins21>Insert21</Ins21>
    <Ins22>Insert22</Ins22>
    <Ins91>Insert91</Ins91>
    <Ins92>Insert92</Ins92>
    <Programs>
      <Program>
        <Type>MA</Type>
      </Program>
      <Program>
        <Type>HP</Type>
      </Program>
    </Programs>
  </Doc>

Open in new window


i want to update the xml as below

<Doc>
   <Ins20>Insert20</Ins20>
    <Ins21>Insert21</Ins21>
    <Ins22>Insert22</Ins22>
     <Ins5>Insert5</Ins5>
    <Ins6>Insert6</Ins6>
    <Ins00>Insert00</Ins00>
     <Ins91>Insert91</Ins91>
    <Ins92>Insert92</Ins92>
    <Programs>
      <Program>
        <Type>MA</Type>
      </Program>
      <Program>
        <Type>HP</Type>
      </Program>
    </Programs>
  </Doc>

Open in new window


I am using the below xsl  (with the help of Member Geert)

<xsl:template match="Doc">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="Ins20"/>
            <xsl:apply-templates select="Ins21"/>
            <xsl:apply-templates select="Ins22"/>
            <xsl:apply-templates select="Ins5"/>
            <xsl:apply-templates select="Ins6"/>
            <xsl:apply-templates select="Ins00"/>
            <xsl:apply-templates select="Ins91"/>
            <xsl:apply-templates select="Ins92"/>
        </xsl:copy>
</xsl:template>

the xsl i s getting me the correct  order but it removing the  <Programs> part, i dont want to disturb the below part
============
 <Programs>
      <Program>
        <Type>MA</Type>
      </Program>
      <Program>
        <Type>HP</Type>
      </Program>
    </Programs>


Thank you in advance.
sri1209Asked:
Who is Participating?
 
Geert BormansInformation ArchitectCommented:
Simply add a apply-templates for adding the programs

<xsl:apply-templates select="Ins92"/>

to become

<xsl:apply-templates select="Ins92"/>
<xsl:apply-templates select="Programs"/>
0
 
sri1209Author Commented:
Thanks Geert, you always have a solution.
0
 
Geert BormansInformation ArchitectCommented:
welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.