当前位置: 首页 > 网络学院 > XML相关教程 > XSL/XSLT > XSLT <xsl:number> 元素
The <xsl:number> element is used to determine the integer position of the current node in the source. It is also used to format a number.
<xsl:number> 元素的作用是:确定数据源中当前节点的整数位置。它也被用来格式化一个数字。
<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"/> |
属性 | 值 | 描述 |
---|---|---|
count | expression | Optional. An XPath expression that specifies what nodes are to be counted 可选参数。指定一个XPath表达式,该表达式是用来指明被计算的结节点对象的 |
level | single multiple any | Optional. Controls how the sequence number is assigned 可选参数。控制分派序列数的方式 Can be one of the following:
|
from | expression | Optional. An XPath expression that specifies where the counting will start 可选参数。指定一个XPath表达式,它是用来指定开始计数的起点 |
value | expression | Optional. Specifies a user-provided number that is used in place of a sequence generated number 可选参数。指定一个用户提供数,该数字是用来代替序列数(按照顺序产生的)的 |
format | formatstring | Optional. Defines the output format for the number. Can be one of the following: 可选参数。为数字定义输出格式。可以是下值中的一个:
|
lang | languagecode | Optional. Specifies the language alphabet to be used for the numbering (Not supported by Netscape 6) 可选参数。指定用于编号的字母(Netscape 6不支持) |
letter-value | alphabetic traditional | Optional. Specifies whether the numbering in the selected language is alphabetic or traditional. The default is alphabetic 可选参数。指定选定的编号方式是字母方式还是使用传统方式。默认值是字母方式 |
grouping-separator | character | Optional. Specifies what character should be used to separate groups of digits. The default is the comma 可选参数。指定数位分割字符。默认是逗点(,) |
grouping-size | number | Optional. Specifies how many digits are in the groups that are being separated by the character specified in the grouping-separator attribute. The default is 3 可选参数。指定以多少个数字为一组对整段数字进行分组。默认是以3个数字为一组 |
<xsl:number value="250000" grouping-separator="."/> 输出结果: 250.000 |
<xsl:number value="250000" grouping-size="2"/> 输出结果: 25,00,00 |
<xsl:number value="12" grouping-size="1" grouping-separator="#" format="I"/> 输出结果: X#I#I |
<?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> |