开发者

How to use xsl number to count elements

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜