Reorder XML nodes based on condition in XSLT












0














I have an input XML that i have to restructure into another XML using XSLT.
The incoming XML looks like this



 <Header>
<Rejection>
<Code>Code1</Code>
<Text>Text1</Text>
</Rejection>
<Rejection>
<Code>Code2</Code>
<Text>Text2</Text>
</Rejection>
<Rejection>
<Code>Code3</Code>
<Text>Text3</Text>
</Rejection>
</Header>


Whenever the Rejection has a code value of Code3 then Code3/Text3 tag has to be the first tag. The position of Code3 could be anywhere in the incoming XML but it has to be the first rejection tag in the output. This is my current XSLT



<xsl:for-each select="/Header/Rejection">
<xsl:if test ="Code='Code3'">
<REJECTION>
<REJECTCODE><xsl:value-of select="Code"></xsl:value-of></REJECTCODE>
<REJECTREASON><xsl:value-of select="Text"></xsl:value-of></REJECTREASON>
</REJECTION>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="/Header/Rejection">
<xsl:if test ="not(Code='Code3')">
<REJECTION>
<REJECTCODE><xsl:value-of select="Code"></xsl:value-of></REJECTCODE>
<REJECTREASON><xsl:value-of select="Text"></xsl:value-of></REJECTREASON>
</REJECTION>
</xsl:if>
</xsl:for-each>


Now is there a way to prevent the 2 loops and get the result in single loop.
The output XML has to be like this:



<Header>
<REJECTION>
<REJECTCODE>Code3</REJECTCODE>
<REJECTREASON>Text3</REJECTREASON>
</REJECTION>
<REJECTION>
<REJECTCODE>Code1</REJECTCODE>
<REJECTREASON>Text1</REJECTREASON>
</REJECTION>
<REJECTION>
<REJECTCODE>Code2</REJECTCODE>
<REJECTREASON>Text2</REJECTREASON>
</REJECTION>
</Header>


Note: The codes are just a sample.It is actually alpha numeric and is not in sortable order.










share|improve this question





























    0














    I have an input XML that i have to restructure into another XML using XSLT.
    The incoming XML looks like this



     <Header>
    <Rejection>
    <Code>Code1</Code>
    <Text>Text1</Text>
    </Rejection>
    <Rejection>
    <Code>Code2</Code>
    <Text>Text2</Text>
    </Rejection>
    <Rejection>
    <Code>Code3</Code>
    <Text>Text3</Text>
    </Rejection>
    </Header>


    Whenever the Rejection has a code value of Code3 then Code3/Text3 tag has to be the first tag. The position of Code3 could be anywhere in the incoming XML but it has to be the first rejection tag in the output. This is my current XSLT



    <xsl:for-each select="/Header/Rejection">
    <xsl:if test ="Code='Code3'">
    <REJECTION>
    <REJECTCODE><xsl:value-of select="Code"></xsl:value-of></REJECTCODE>
    <REJECTREASON><xsl:value-of select="Text"></xsl:value-of></REJECTREASON>
    </REJECTION>
    </xsl:if>
    </xsl:for-each>
    <xsl:for-each select="/Header/Rejection">
    <xsl:if test ="not(Code='Code3')">
    <REJECTION>
    <REJECTCODE><xsl:value-of select="Code"></xsl:value-of></REJECTCODE>
    <REJECTREASON><xsl:value-of select="Text"></xsl:value-of></REJECTREASON>
    </REJECTION>
    </xsl:if>
    </xsl:for-each>


    Now is there a way to prevent the 2 loops and get the result in single loop.
    The output XML has to be like this:



    <Header>
    <REJECTION>
    <REJECTCODE>Code3</REJECTCODE>
    <REJECTREASON>Text3</REJECTREASON>
    </REJECTION>
    <REJECTION>
    <REJECTCODE>Code1</REJECTCODE>
    <REJECTREASON>Text1</REJECTREASON>
    </REJECTION>
    <REJECTION>
    <REJECTCODE>Code2</REJECTCODE>
    <REJECTREASON>Text2</REJECTREASON>
    </REJECTION>
    </Header>


    Note: The codes are just a sample.It is actually alpha numeric and is not in sortable order.










    share|improve this question



























      0












      0








      0







      I have an input XML that i have to restructure into another XML using XSLT.
      The incoming XML looks like this



       <Header>
      <Rejection>
      <Code>Code1</Code>
      <Text>Text1</Text>
      </Rejection>
      <Rejection>
      <Code>Code2</Code>
      <Text>Text2</Text>
      </Rejection>
      <Rejection>
      <Code>Code3</Code>
      <Text>Text3</Text>
      </Rejection>
      </Header>


      Whenever the Rejection has a code value of Code3 then Code3/Text3 tag has to be the first tag. The position of Code3 could be anywhere in the incoming XML but it has to be the first rejection tag in the output. This is my current XSLT



      <xsl:for-each select="/Header/Rejection">
      <xsl:if test ="Code='Code3'">
      <REJECTION>
      <REJECTCODE><xsl:value-of select="Code"></xsl:value-of></REJECTCODE>
      <REJECTREASON><xsl:value-of select="Text"></xsl:value-of></REJECTREASON>
      </REJECTION>
      </xsl:if>
      </xsl:for-each>
      <xsl:for-each select="/Header/Rejection">
      <xsl:if test ="not(Code='Code3')">
      <REJECTION>
      <REJECTCODE><xsl:value-of select="Code"></xsl:value-of></REJECTCODE>
      <REJECTREASON><xsl:value-of select="Text"></xsl:value-of></REJECTREASON>
      </REJECTION>
      </xsl:if>
      </xsl:for-each>


      Now is there a way to prevent the 2 loops and get the result in single loop.
      The output XML has to be like this:



      <Header>
      <REJECTION>
      <REJECTCODE>Code3</REJECTCODE>
      <REJECTREASON>Text3</REJECTREASON>
      </REJECTION>
      <REJECTION>
      <REJECTCODE>Code1</REJECTCODE>
      <REJECTREASON>Text1</REJECTREASON>
      </REJECTION>
      <REJECTION>
      <REJECTCODE>Code2</REJECTCODE>
      <REJECTREASON>Text2</REJECTREASON>
      </REJECTION>
      </Header>


      Note: The codes are just a sample.It is actually alpha numeric and is not in sortable order.










      share|improve this question















      I have an input XML that i have to restructure into another XML using XSLT.
      The incoming XML looks like this



       <Header>
      <Rejection>
      <Code>Code1</Code>
      <Text>Text1</Text>
      </Rejection>
      <Rejection>
      <Code>Code2</Code>
      <Text>Text2</Text>
      </Rejection>
      <Rejection>
      <Code>Code3</Code>
      <Text>Text3</Text>
      </Rejection>
      </Header>


      Whenever the Rejection has a code value of Code3 then Code3/Text3 tag has to be the first tag. The position of Code3 could be anywhere in the incoming XML but it has to be the first rejection tag in the output. This is my current XSLT



      <xsl:for-each select="/Header/Rejection">
      <xsl:if test ="Code='Code3'">
      <REJECTION>
      <REJECTCODE><xsl:value-of select="Code"></xsl:value-of></REJECTCODE>
      <REJECTREASON><xsl:value-of select="Text"></xsl:value-of></REJECTREASON>
      </REJECTION>
      </xsl:if>
      </xsl:for-each>
      <xsl:for-each select="/Header/Rejection">
      <xsl:if test ="not(Code='Code3')">
      <REJECTION>
      <REJECTCODE><xsl:value-of select="Code"></xsl:value-of></REJECTCODE>
      <REJECTREASON><xsl:value-of select="Text"></xsl:value-of></REJECTREASON>
      </REJECTION>
      </xsl:if>
      </xsl:for-each>


      Now is there a way to prevent the 2 loops and get the result in single loop.
      The output XML has to be like this:



      <Header>
      <REJECTION>
      <REJECTCODE>Code3</REJECTCODE>
      <REJECTREASON>Text3</REJECTREASON>
      </REJECTION>
      <REJECTION>
      <REJECTCODE>Code1</REJECTCODE>
      <REJECTREASON>Text1</REJECTREASON>
      </REJECTION>
      <REJECTION>
      <REJECTCODE>Code2</REJECTCODE>
      <REJECTREASON>Text2</REJECTREASON>
      </REJECTION>
      </Header>


      Note: The codes are just a sample.It is actually alpha numeric and is not in sortable order.







      xslt






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 23:26







      NiranjanKC

















      asked Nov 19 '18 at 19:33









      NiranjanKCNiranjanKC

      34




      34
























          2 Answers
          2






          active

          oldest

          votes


















          0














          How about:



          <xsl:stylesheet version="1.0" 
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
          <xsl:strip-space elements="*"/>

          <xsl:template match="/Header">
          <xsl:copy>
          <xsl:apply-templates select="Rejection">
          <xsl:sort select="number(Code='Code3')" data-type="number" order="descending"/>
          </xsl:apply-templates>
          </xsl:copy>
          </xsl:template>

          <xsl:template match="Rejection">
          <REJECTION>
          <REJECTCODE>
          <xsl:value-of select="Code"/>
          </REJECTCODE>
          <REJECTREASON>
          <xsl:value-of select="Text"/>
          </REJECTREASON>
          </REJECTION>
          </xsl:template>

          </xsl:stylesheet>





          share|improve this answer























          • I am sorry i should have been clear.The codes i have mentioned are mocked up. It wont be in sorting order.It is alpha numeric code.I have changed the question to reflect that.
            – NiranjanKC
            Nov 19 '18 at 23:26










          • @NiranjanKC I don't see anything new that would require changing my answer. The code can be anything you want. I am not sorting by the code. I am sorting by the code being equal to a given string.
            – michael.hor257k
            Nov 19 '18 at 23:30










          • Is there an alternative to this <xsl:template match="Rejection">. I am not able to use this condition as the XSLT already has a template defined at the root Header level(It has a bunch of other tags in between).Whatever i try is printing all the tag contents of Rejection in it?
            – NiranjanKC
            Nov 20 '18 at 15:46












          • I am afraid I don't understand what you're saying.
            – michael.hor257k
            Nov 20 '18 at 15:56










          • My XSLT has a <xsl:template match="/"> at the top and closes at the last line. I am not able to put this <xsl:template match="Rejection"> in between.
            – NiranjanKC
            Nov 20 '18 at 16:58



















          -1














          <xsl:template match="@*|node()">
          <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
          </xsl:template>
          <xsl:template match="Header">
          <xsl:copy>
          <xsl:apply-templates select="Rejection[3]"/>
          <xsl:apply-templates select="Rejection[1]"/>
          <xsl:apply-templates select="Rejection[2]"/>
          </xsl:copy>
          </xsl:template>
          You may simply apply according to your need.





          share|improve this answer





















          • The question says clearly: "The position of Code3 could be anywhere in the incoming XML".
            – michael.hor257k
            Nov 21 '18 at 5:51











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53381440%2freorder-xml-nodes-based-on-condition-in-xslt%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          How about:



          <xsl:stylesheet version="1.0" 
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
          <xsl:strip-space elements="*"/>

          <xsl:template match="/Header">
          <xsl:copy>
          <xsl:apply-templates select="Rejection">
          <xsl:sort select="number(Code='Code3')" data-type="number" order="descending"/>
          </xsl:apply-templates>
          </xsl:copy>
          </xsl:template>

          <xsl:template match="Rejection">
          <REJECTION>
          <REJECTCODE>
          <xsl:value-of select="Code"/>
          </REJECTCODE>
          <REJECTREASON>
          <xsl:value-of select="Text"/>
          </REJECTREASON>
          </REJECTION>
          </xsl:template>

          </xsl:stylesheet>





          share|improve this answer























          • I am sorry i should have been clear.The codes i have mentioned are mocked up. It wont be in sorting order.It is alpha numeric code.I have changed the question to reflect that.
            – NiranjanKC
            Nov 19 '18 at 23:26










          • @NiranjanKC I don't see anything new that would require changing my answer. The code can be anything you want. I am not sorting by the code. I am sorting by the code being equal to a given string.
            – michael.hor257k
            Nov 19 '18 at 23:30










          • Is there an alternative to this <xsl:template match="Rejection">. I am not able to use this condition as the XSLT already has a template defined at the root Header level(It has a bunch of other tags in between).Whatever i try is printing all the tag contents of Rejection in it?
            – NiranjanKC
            Nov 20 '18 at 15:46












          • I am afraid I don't understand what you're saying.
            – michael.hor257k
            Nov 20 '18 at 15:56










          • My XSLT has a <xsl:template match="/"> at the top and closes at the last line. I am not able to put this <xsl:template match="Rejection"> in between.
            – NiranjanKC
            Nov 20 '18 at 16:58
















          0














          How about:



          <xsl:stylesheet version="1.0" 
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
          <xsl:strip-space elements="*"/>

          <xsl:template match="/Header">
          <xsl:copy>
          <xsl:apply-templates select="Rejection">
          <xsl:sort select="number(Code='Code3')" data-type="number" order="descending"/>
          </xsl:apply-templates>
          </xsl:copy>
          </xsl:template>

          <xsl:template match="Rejection">
          <REJECTION>
          <REJECTCODE>
          <xsl:value-of select="Code"/>
          </REJECTCODE>
          <REJECTREASON>
          <xsl:value-of select="Text"/>
          </REJECTREASON>
          </REJECTION>
          </xsl:template>

          </xsl:stylesheet>





          share|improve this answer























          • I am sorry i should have been clear.The codes i have mentioned are mocked up. It wont be in sorting order.It is alpha numeric code.I have changed the question to reflect that.
            – NiranjanKC
            Nov 19 '18 at 23:26










          • @NiranjanKC I don't see anything new that would require changing my answer. The code can be anything you want. I am not sorting by the code. I am sorting by the code being equal to a given string.
            – michael.hor257k
            Nov 19 '18 at 23:30










          • Is there an alternative to this <xsl:template match="Rejection">. I am not able to use this condition as the XSLT already has a template defined at the root Header level(It has a bunch of other tags in between).Whatever i try is printing all the tag contents of Rejection in it?
            – NiranjanKC
            Nov 20 '18 at 15:46












          • I am afraid I don't understand what you're saying.
            – michael.hor257k
            Nov 20 '18 at 15:56










          • My XSLT has a <xsl:template match="/"> at the top and closes at the last line. I am not able to put this <xsl:template match="Rejection"> in between.
            – NiranjanKC
            Nov 20 '18 at 16:58














          0












          0








          0






          How about:



          <xsl:stylesheet version="1.0" 
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
          <xsl:strip-space elements="*"/>

          <xsl:template match="/Header">
          <xsl:copy>
          <xsl:apply-templates select="Rejection">
          <xsl:sort select="number(Code='Code3')" data-type="number" order="descending"/>
          </xsl:apply-templates>
          </xsl:copy>
          </xsl:template>

          <xsl:template match="Rejection">
          <REJECTION>
          <REJECTCODE>
          <xsl:value-of select="Code"/>
          </REJECTCODE>
          <REJECTREASON>
          <xsl:value-of select="Text"/>
          </REJECTREASON>
          </REJECTION>
          </xsl:template>

          </xsl:stylesheet>





          share|improve this answer














          How about:



          <xsl:stylesheet version="1.0" 
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
          <xsl:strip-space elements="*"/>

          <xsl:template match="/Header">
          <xsl:copy>
          <xsl:apply-templates select="Rejection">
          <xsl:sort select="number(Code='Code3')" data-type="number" order="descending"/>
          </xsl:apply-templates>
          </xsl:copy>
          </xsl:template>

          <xsl:template match="Rejection">
          <REJECTION>
          <REJECTCODE>
          <xsl:value-of select="Code"/>
          </REJECTCODE>
          <REJECTREASON>
          <xsl:value-of select="Text"/>
          </REJECTREASON>
          </REJECTION>
          </xsl:template>

          </xsl:stylesheet>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 20 '18 at 12:31

























          answered Nov 19 '18 at 19:44









          michael.hor257kmichael.hor257k

          73.9k42236




          73.9k42236












          • I am sorry i should have been clear.The codes i have mentioned are mocked up. It wont be in sorting order.It is alpha numeric code.I have changed the question to reflect that.
            – NiranjanKC
            Nov 19 '18 at 23:26










          • @NiranjanKC I don't see anything new that would require changing my answer. The code can be anything you want. I am not sorting by the code. I am sorting by the code being equal to a given string.
            – michael.hor257k
            Nov 19 '18 at 23:30










          • Is there an alternative to this <xsl:template match="Rejection">. I am not able to use this condition as the XSLT already has a template defined at the root Header level(It has a bunch of other tags in between).Whatever i try is printing all the tag contents of Rejection in it?
            – NiranjanKC
            Nov 20 '18 at 15:46












          • I am afraid I don't understand what you're saying.
            – michael.hor257k
            Nov 20 '18 at 15:56










          • My XSLT has a <xsl:template match="/"> at the top and closes at the last line. I am not able to put this <xsl:template match="Rejection"> in between.
            – NiranjanKC
            Nov 20 '18 at 16:58


















          • I am sorry i should have been clear.The codes i have mentioned are mocked up. It wont be in sorting order.It is alpha numeric code.I have changed the question to reflect that.
            – NiranjanKC
            Nov 19 '18 at 23:26










          • @NiranjanKC I don't see anything new that would require changing my answer. The code can be anything you want. I am not sorting by the code. I am sorting by the code being equal to a given string.
            – michael.hor257k
            Nov 19 '18 at 23:30










          • Is there an alternative to this <xsl:template match="Rejection">. I am not able to use this condition as the XSLT already has a template defined at the root Header level(It has a bunch of other tags in between).Whatever i try is printing all the tag contents of Rejection in it?
            – NiranjanKC
            Nov 20 '18 at 15:46












          • I am afraid I don't understand what you're saying.
            – michael.hor257k
            Nov 20 '18 at 15:56










          • My XSLT has a <xsl:template match="/"> at the top and closes at the last line. I am not able to put this <xsl:template match="Rejection"> in between.
            – NiranjanKC
            Nov 20 '18 at 16:58
















          I am sorry i should have been clear.The codes i have mentioned are mocked up. It wont be in sorting order.It is alpha numeric code.I have changed the question to reflect that.
          – NiranjanKC
          Nov 19 '18 at 23:26




          I am sorry i should have been clear.The codes i have mentioned are mocked up. It wont be in sorting order.It is alpha numeric code.I have changed the question to reflect that.
          – NiranjanKC
          Nov 19 '18 at 23:26












          @NiranjanKC I don't see anything new that would require changing my answer. The code can be anything you want. I am not sorting by the code. I am sorting by the code being equal to a given string.
          – michael.hor257k
          Nov 19 '18 at 23:30




          @NiranjanKC I don't see anything new that would require changing my answer. The code can be anything you want. I am not sorting by the code. I am sorting by the code being equal to a given string.
          – michael.hor257k
          Nov 19 '18 at 23:30












          Is there an alternative to this <xsl:template match="Rejection">. I am not able to use this condition as the XSLT already has a template defined at the root Header level(It has a bunch of other tags in between).Whatever i try is printing all the tag contents of Rejection in it?
          – NiranjanKC
          Nov 20 '18 at 15:46






          Is there an alternative to this <xsl:template match="Rejection">. I am not able to use this condition as the XSLT already has a template defined at the root Header level(It has a bunch of other tags in between).Whatever i try is printing all the tag contents of Rejection in it?
          – NiranjanKC
          Nov 20 '18 at 15:46














          I am afraid I don't understand what you're saying.
          – michael.hor257k
          Nov 20 '18 at 15:56




          I am afraid I don't understand what you're saying.
          – michael.hor257k
          Nov 20 '18 at 15:56












          My XSLT has a <xsl:template match="/"> at the top and closes at the last line. I am not able to put this <xsl:template match="Rejection"> in between.
          – NiranjanKC
          Nov 20 '18 at 16:58




          My XSLT has a <xsl:template match="/"> at the top and closes at the last line. I am not able to put this <xsl:template match="Rejection"> in between.
          – NiranjanKC
          Nov 20 '18 at 16:58













          -1














          <xsl:template match="@*|node()">
          <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
          </xsl:template>
          <xsl:template match="Header">
          <xsl:copy>
          <xsl:apply-templates select="Rejection[3]"/>
          <xsl:apply-templates select="Rejection[1]"/>
          <xsl:apply-templates select="Rejection[2]"/>
          </xsl:copy>
          </xsl:template>
          You may simply apply according to your need.





          share|improve this answer





















          • The question says clearly: "The position of Code3 could be anywhere in the incoming XML".
            – michael.hor257k
            Nov 21 '18 at 5:51
















          -1














          <xsl:template match="@*|node()">
          <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
          </xsl:template>
          <xsl:template match="Header">
          <xsl:copy>
          <xsl:apply-templates select="Rejection[3]"/>
          <xsl:apply-templates select="Rejection[1]"/>
          <xsl:apply-templates select="Rejection[2]"/>
          </xsl:copy>
          </xsl:template>
          You may simply apply according to your need.





          share|improve this answer





















          • The question says clearly: "The position of Code3 could be anywhere in the incoming XML".
            – michael.hor257k
            Nov 21 '18 at 5:51














          -1












          -1








          -1






          <xsl:template match="@*|node()">
          <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
          </xsl:template>
          <xsl:template match="Header">
          <xsl:copy>
          <xsl:apply-templates select="Rejection[3]"/>
          <xsl:apply-templates select="Rejection[1]"/>
          <xsl:apply-templates select="Rejection[2]"/>
          </xsl:copy>
          </xsl:template>
          You may simply apply according to your need.





          share|improve this answer












          <xsl:template match="@*|node()">
          <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
          </xsl:template>
          <xsl:template match="Header">
          <xsl:copy>
          <xsl:apply-templates select="Rejection[3]"/>
          <xsl:apply-templates select="Rejection[1]"/>
          <xsl:apply-templates select="Rejection[2]"/>
          </xsl:copy>
          </xsl:template>
          You may simply apply according to your need.






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 5:22









          imranimran

          17317




          17317












          • The question says clearly: "The position of Code3 could be anywhere in the incoming XML".
            – michael.hor257k
            Nov 21 '18 at 5:51


















          • The question says clearly: "The position of Code3 could be anywhere in the incoming XML".
            – michael.hor257k
            Nov 21 '18 at 5:51
















          The question says clearly: "The position of Code3 could be anywhere in the incoming XML".
          – michael.hor257k
          Nov 21 '18 at 5:51




          The question says clearly: "The position of Code3 could be anywhere in the incoming XML".
          – michael.hor257k
          Nov 21 '18 at 5:51


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53381440%2freorder-xml-nodes-based-on-condition-in-xslt%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith