tags:

views:

280

answers:

2

I am writing a transform for a set of nodes, 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 top down (recursive):

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

The problem is after it generates the 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 am out of ideas on how to resort this after recursion? Should I use another template and implement apply-templates or is there a another way I can reverse the order?

+1  A: 

What if you add the recursive call before the do stuff?

  <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.

pgb
Thank you, :) it seems that did the trick, would have never thought about trying that, it makes sense without making sense :D
Andrew
A: 

To understand recursion, first you must understand recursion.