Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XSLT <xsl:number> elements


May 28, 2021 XSL T


Table of contents


XSLT and lt;xsl: number.gt; elements

The XSLT-lt;xsl:number-and-gt; element can be used to determine both the location of integers in the current node and to format a number.


XSLT <xsl:number> elements Complete XSLT element reference manual

Definitions and usages

The element is used to determine the integer position of the current node in the source. It is also used to format numbers.


Grammar

<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"/>

Property

属性 描述
count expression 可选。一个 XPath 表达式,规定要计数的节点。
level single
multiple
any
可选。控制如何分配序号。

可以使用的值:

  • single (默认)
  • multiple
  • any (Netscape 6 不支持)
from expression 可选。一个 XPath 表达式,规定从何处开始计数。
value expression 可选。规定用户提供的数字,用于代替产生的序号。
format formatstring 可选。定义数字的输出格式。可以使用的值:
  • format="1" 结果 1 2 3 . .
  • format="01" 结果 01 02 03 (Netscape 6 不支持)
  • format="a" 结果 a b c . . (Netscape 6 不支持)
  • format="A" 结果 A B C. . (Netscape 6 不支持)
  • format="i" 结果 i ii iii iv . . (Netscape 6 不支持)
  • format="I" 结果 I II III IV . . (Netscape 6 不支持)
lang languagecode 可选。规定用于编号的语言字母表。(Netscape 6 不支持)
letter-value alphabetic
traditional
可选。规定选定语言的编号是字母序列("alphabetic")还是其他序列("traditional")。值 "alphabetic" 指定字母序列;值 "traditional" 指定其他序列。默认是 "alphabetic"。
grouping-separator character 可选。规定使用什么字符来分隔组或数字。默认是逗号。
grouping-size number 可选。规定由 grouping-separator 属性指定的分隔字符分隔的每个分组中的数字个数。默认是 3。

Instance 1

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

Output:

250.000

Instance 2

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

Output:

25,00,00

Instance 3

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

Output:

X#I#I

Instance 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:number> elements Complete XSLT element reference manual