XSLT Reverse Order Templates Using Application Templates or Calling Patterns?

I am writing a transform for a nodeset similar to this.

  <xsl:template match="/" name="nav">
        <!--do stuff-->
      <xsl:if test="notEnd">
       <xsl:call-template name="nav"></xsl:call-template>
      </xsl:if>
  </xsl:template>

      

The result it generates is from top to bottom (recursive):

<!--do stuff 5-->
<!--do stuff 4-->
<!--do stuff 3-->
<!--do stuff 2-->
<!--do stuff 1-->

      

The problem is that it generates a result, I need it to be in the correct order:

<!--do stuff 1-->
<!--do stuff 2-->
<!--do stuff 3-->
<!--do stuff 4-->
<!--do stuff 5-->

      

I'm out of ideas on how to resort to this after recursion? Should I use a different template and embed the app templates or is there some other way that I can change the order?

+1


a source to share


2 answers


What if you add a recursive call before doing so?

  <xsl:template match="/" name="nav">
      <xsl:if test="notEnd">
       <xsl:call-template name="nav"></xsl:call-template>
      </xsl:if>
      <!--do stuff-->
  </xsl:template>

      



You should get the reverse order.

+1


a source


To understand recursion, you must first understand recursion.



0


a source







All Articles