10

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>

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!

1 Answer 1

18

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.