xsl:decimal-format
xsl:value-of
ELEMENT: xsl:number
<xsl:number
count="pattern"
format="{ string }"
from="pattern"
grouping-separator="{ character }"
grouping-size="{ number }"
lang="{ languagecode }"
letter-value={ "alphabetic" | "traditional" }
level="any" | "multiple" | "single"
value="expression"
>
</xsl:number>
The
xsl:number
element has two possible uses. It can determine the sequence number for the current node and it can format a number for display in the output.
The sequence number is the integer position of the current node in a source document (source tree). There are actually three ways that the sequence number can be determined and you can use the
level
attribute to choose which way.
The formatting process converts either the sequence number or the number provided by the
value
attribute to a string. By using various attributes of the
xsl:number
element, you can exert great control over the appearance of the formatted number in the output.
In comparison, the
xsl:decimal-format
element defines the symbols and characters used by the
format-number
function to convert numbers to strings.
This is a self-closing element and it cannot contain any child elements or any content.
count="pattern"
The optional
count
attribute dictates what nodes are to be counted. Only nodes that match the pattern are counted. The default is to count any node that matches the pattern of the current node.
format="{ string }"
The optional
format
attribute is set to an Attribute Value Template that dictates the output format for the number. You can use any the following choices:
Format
Output Sequence
1
1 2 3 4 ... 10 11 12 ...
01
01 02 03 04 ... 10 11 12 ...
a
a b c ... z aa ab ac ...
A
A B C ... Z AA AB AC ...
i
i ii iii iv v vi vii viii ix x ...
I
I II II IV V VI VII VIII IX X ...
For example,
format="1.A.a. "
would allow the appropriate paragraph to be numbered 6.C.b.
from="pattern"
The optional
from
attribute specifies a starting point from which the sequential counting will start. The nodes are matched to the pattern to find the starting point.
grouping-separator="{ character }"
The optional
grouping-separator
attribute is set to an Attribute Value Template or a character that dictates what character is to be used to separate groups of digits in the number being displayed in the output. White-space is permitted. The
grouping-separator
attribute is ignored if you do not also set the
grouping-size
attribute to the digit group size. The classic example is to use a comma to separate groups of three digits.
grouping-size="{ number }"
The optional
grouping-size
attribute is set to an Attribute Value Template or a number that dictates how many digits are in the groups that are being separated by the character specified in the
grouping-separator
attribute. The
grouping-size
attribute is ignored if you do not also use the
grouping-separator
attribute to specify a separator. The classic example are groups of three digits separated by a comma.
lang="{ languagecode }"
The optional
lang
attribute is set to an Attribute Value Template or a string that dictates the language code which in turn specifies the language alphabet to be used for the numbering. The default language is set by the operating system environment.
letter-value="{ alphabetic | traditional }"
The optional
letter-value
attribute is set to an Attribute Value Template that dictates whether the numbering sequence in the selected language is either alphabetic or traditional. Or it can be set directly to either one of the two permitted values. The primary example is Traditional Hebrew versus Alphabetic Hebrew. The default is alphabetic.
level="any" | "multiple" | "single"
The optional
level
attribute is set to an Attribute Value Template that controls how the sequence number is assigned. Or it can be set directly to one of the three permitted values. There are only three permitted procedures for determining a sequence number:
Level
Effect
single
The default value. All preceding nodes that match the target node pattern are counted. Limitations imposed by the
from
and
count
attributes are obeyed. The sequence starts at one. If the current target node has four preceding nodes, then the current target node will be given the sequence number of five.
multiple
First, a list is constructed of all ancestors of the current node. The list goes back to, but does not include, the ancestor that matches the optional
from
attribute pattern. Next, for each node in the list that matches the
count
pattern, the XSL processor maps how many preceding siblings of that node match the
count
pattern. This hierarchic position information is provided in a composite sequence number list.
any
Starting from the current node, the XSL processor counts how many nodes match the
count
attribute pattern. If a node specified in the optional
from
attribute is encountered, the counting process stops. The sequence number is the number of nodes counted. This can be zero, if the current node does not match the
count
pattern.
value="expression"
The optional
value
attribute is a user-provided number that is used in place of a sequence generated number. If the expression generates a real number, it will be rounded and converted to an integer. The default is to use a sequence number which is based upon the current node's position in the source document (source tree).
We use the
DevGuru Staff List XML file
for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_number.xsl"?>
and we name it: xslt_example_number.xml
Code for xslt_example_numbert.xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="devguru_staff/programmer">
<
xsl:number value="position()" format="1. " /
>
<xsl:value-of select="name" />
<br />
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:
Click to view output in separate window
- requires Internet Explorer
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information