开发者

How to use xsl number to count elements

开发者 https://www.devze.com 2023-02-22 18:34 出处:网络
Below I am counting elements using xsl:number. I would like to count the chapters in order, see below:

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:v开发者_运维问答alue-of select="$chapNum"/>
</xsl:template>

OUTPUT:

1
1
1
2

Desired OUTPUT:

1
2
3
4

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

Thanks for any help in advance!


Use <xsl:number level="any"/>

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号