XSLT <xsl:number>Element


XSLT 元素参考手册Complete XSLT Element Reference

Definition and Usage

The <xsl:number> element is used to determine the integer position of the current node in the source. It is also used to format numbers.


Syntax

<xsl:number
count="expression"
level="single|multiple|any"
from="expression"
value="expression"
format="formatstring"
lang="languagecode"
letter-value="alphabetic|traditional"
grouping-separator="character"
grouping-size="number"/>

Attributes

Attribute Value Description
count expression Optional. An XPath expression that specifies the nodes to be counted.
level single
multiple
any
Optional. Controls how sequence numbers are assigned.

Possible values:

  • single (default)
  • multiple
  • any (not supported in Netscape 6)
from expression Optional. An XPath expression that specifies where to start counting.
value expression Optional. Specifies a user-provided number to be used in place of the generated sequence number.
format formatstring Optional. Defines the output format of the numbers. Possible values:
  • format="1" results in 1 2 3 . .
  • format="01" results in 01 02 03 (not supported in Netscape 6)
  • format="a" results in a b c . . (not supported in Netscape 6)
  • format="A" results in A B C . . (not supported in Netscape 6)
  • format="i" results in i ii iii iv . . (not supported in Netscape 6)
  • format="I" results in I II III IV . . (not supported in Netscape 6)
lang languagecode Optional. Specifies the language alphabet to be used for numbering. (Not supported in Netscape 6)
letter-value alphabetic
traditional
Optional. Specifies whether the numbering for the selected language is an alphabetic sequence ("alphabetic") or another sequence ("traditional"). The value "alphabetic" specifies an alphabetic sequence; the value "traditional" specifies another sequence. Default is "alphabetic".
grouping-separator character Optional. Specifies which character to use to separate groups or digits. Default is comma.
grouping-size number Optional. Specifies the number of digits in each group separated by the separator character specified by the grouping-separator attribute. Default is 3.

Example 1

<xsl:number value="250000" grouping-separator="."/>

Output:

250.000

Example 2

<xsl:number value="250000" grouping-size="2"/>

Output:

25,00,00

Example 3

<xsl:number value="12" grouping-size="1"
grouping-separator="#" format="I"/>

Output:

X#I#I

Example 4

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<p>
<xsl:for-each select="catalog/cd">
<xsl:number value="position()" format="1" />
<xsl:value-of select="title" /><br />
</xsl:for-each>
</p>
</body>
</html>
</xsl:template>

</xsl:stylesheet>


XSLT 元素参考手册Complete XSLT Element Reference Other Extensions