We help IT Professionals succeed at work.

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.
Comment
Watch Question

Information Architect
Top Expert 2006
Commented:
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"/>

Author

Commented:
Thanks Geert, you always have a solution.
Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
welcome