XSLT 通过 apply-template 或 call-template 反转模板顺序?

发布于 2024-07-19 08:19:25 字数 700 浏览 5 评论 0原文

我正在为一组节点编写一个转换,与此类似。

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

它生成的结果是自上而下的(递归):

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

问题是在它生成结果之后,我需要它按正确的顺序:

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

我不知道如何在递归后使用它? 我应该使用另一个模板并实施 apply-templates 还是有其他方法可以反转顺序?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痞味浪人 2024-07-26 08:19:25

如果在 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>

你应该得到相反的顺序。

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.

话少情深 2024-07-26 08:19:25

要理解递归,首先必须理解递归。

To understand recursion, first you must understand recursion.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文