如何使用 xsl number 计算元素 [英] How to use xsl number to count elements

查看:22
本文介绍了如何使用 xsl number 计算元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面我使用 xsl:number 计算元素.我想按章数,见下图:

Below I am counting elements using xsl:number. I would like to count the chapters in order, see below:

XML:

<map>
  <part>
   <chapter/>
  </part>
  <chapter/>
  <part>
   <chapter/>
   <chapter/>
  </part>
</map>

XSLT:

<xsl:template match="chapter">
  <xsl:variable name="chapNum">
    <xsl:number count="chapter" format="1"/>
  </xsl:variable>
  <xsl:value-of select="$chapNum"/>
</xsl:template>

输出:

1
1
1
2

期望的输出:

1
2
3
4

我相信我需要使用 from 属性,但我不确定如何实现它.

I believe I need to use the from attribute but I am not sure how to implement it.

提前感谢您的帮助!

推荐答案

使用

这篇关于如何使用 xsl number 计算元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆