XSLT <xsl:number> 元素
定義和用法
<xsl:number> 元素用于測(cè)定在源中當(dāng)前節(jié)點(diǎn)的整數(shù)位置。它也用于將格式化的數(shù)字插入結(jié)果樹。
語(yǔ)法
<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 表達(dá)式,規(guī)定要計(jì)算的節(jié)點(diǎn)。 |
| level |
|
可選?刂迫绾畏峙湫蛱(hào)。 值可以是:
|
| from | expression | 可選。XPath 表達(dá)式,規(guī)定從何處開始計(jì)數(shù)。 |
| value | expression | 可選。規(guī)定用戶提供的數(shù)字,用于代替產(chǎn)生的序號(hào)。 |
| format | formatstring | 可選。定義數(shù)字的輸出格式。可以使用的值。 |
| lang | languagecode | 可選。規(guī)定用于編號(hào)的語(yǔ)言字母表。 |
| letter-value | alphabetic traditional | 可選。消除使用字母的編號(hào)序列之間的歧義。值 "alphabetic" 指定字母序列;值 "traditional" 指定其他序列。默認(rèn)值為 "alphabetic"。 |
| grouping-separator | character | 可選。規(guī)定使用什么字符來(lái)分隔組或數(shù)字。默認(rèn)是逗號(hào)。 |
| grouping-size | number | 可選。規(guī)定分組的大小。默認(rèn)是 3。 |
格式標(biāo)記
| 格式標(biāo)記 | 生成的序列 |
|---|---|
| 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 不支持的標(biāo)記:01、a、A、i、I。
實(shí)例
例子 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>