XSLT <xsl: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 | 可選。XPath 表達式,規定要計算的節點。 |
level |
| 可選。控制如何分配序號。 值可以是:
|
from | expression | 可選。XPath 表達式,規定從何處開始計數。 |
value | expression | 可選。規定用戶提供的數字,用于代替產生的序號。 |
format | formatstring | 可選。定義數字的輸出格式。可以使用的值。 |
lang | languagecode | 可選。規定用于編號的語言字母表。 |
letter-value | alphabetic traditional | 可選。消除使用字母的編號序列之間的歧義。值 "alphabetic" 指定字母序列;值 "traditional" 指定其他序列。默認值為 "alphabetic"。 |
grouping-separator | character | 可選。規定使用什么字符來分隔組或數字。默認是逗號。 |
grouping-size | number | 可選。規定分組的大小。默認是 3。 |
格式標記
格式標記 | 生成的序列 |
---|---|
1 | 1 2 3 4 5 ... 10 11 12 ... |
01 | 01 02 03 ... 19 10 11 ... 99 100 101... |
a | a b c . . |
A | A B C ...Z AA AB AC... |
i | i ii iii iv v vi vii viii ix x... |
I | I II III IV V VI VII VIII IX X... |
注釋:Netscape 6 不支持的標記:01、a、A、i、I。
實例
例子 1
<xsl:number value="250000" grouping-separator="."/>
輸出:
250.000
例子 2
<xsl:number value="250000" grouping-size="2"/>
輸出:
25,00,00
例子 3
<xsl:number value="12" grouping-size="1" grouping-separator="#" format="I"/>
輸出:
X#I#I
例子 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 <xsl:stylesheet> 和 <xs 下一篇: XSLT <xsl:fallback> 元素