Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

To understand recursion, first you must understand recursion.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top