Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

number

Syntax

Description

Generate a formatted number string, which is output to the result tree. When used with an argument, the statement formats the number given by that XPath expression. When used without an argument, the statement uses the count, from, and level options to generate the number based on the position of one or more nodes within the current XML document. In both cases, optional statements specify the formatting for that number. If needed, you can also redirect the formatted number string to a variable or output method instead of the result tree.

Attributes

number expression

XPath expression providing the number to format.

count nodes

XPath expression specifying which nodes should be counted. If count is omitted, it defaults to nodes with the same name as the current node.

format numbering-style

A string, variable, or XPath expression that defines the number formatting.

The format option can include the following:

  • start string–Any non-alphanumeric characters that precede the first number token in the format string. The start string is prepended to the formatted number string.

  • number token–One or more number tokens that indicate what numbering format to use for the included numbers. The formatted number string only includes more than one number if the level option is set to “multiple”. Table 1 lists format values and corresponding styles. The default value is “1”, which uses a decimal format style. When using decimal format, you can specify the minimum length of the formatted number string by preceding the “1” with one or more zeros.

  • token separator–Non-alphanumeric characters that separate number tokens in the format string. These characters are included in the formatted number string between the computed numbers.

  • end string–Any non-alphanumeric characters that follow the last number token in the format string. The end string is appended to the formatted number string.

Table 1: Numbering Styles for SLAX Statement number, format Option

Format Value

Style

Example

1

Decimal format

1 2 3 ...10 11 ...

01

Decimal format with a minimum output string length of 2

01 02 03 ... 10 11 ...

001

Decimal format with a minimum output string length of 3

001 002 003 ... 010 011 012 ... 100, 101

a

Lowercase alphabetic numbering

a b c ... z ... aa ab ... az ... ba bb ...

A

Uppercase alphabetic numbering

A B C ... Z ... AA AB ... BA BB ...

i

Lowercase Roman numbering

i ii iii iv v ...

I

Uppercase Roman numbering

I II III IV V ...

from nodes

XPath expression specifying from which element to start the count. When level is set to single or multiple, this option constrains the counting to only node descendants of the nearest ancestor that matches the expression. When level is set to any, this option constrains the counting to only nodes that follow the nearest ancestor or preceding node of the current node that matches the expression.

grouping-separator character

Character used to delimit groups of digits for numbers expressed in decimal format. For example, decimal notation uses a comma as the delimiter between digit groupings.

grouping-size number

Defines the number of digits in a group for numbers expressed in decimal format. Setting this option causes the formatted number to be split into multiple groups according to the grouping size, with the grouping separator delimiting the groups. For example, decimal notation often uses a grouping size of 3.

level

Specifies what type of counting to perform. Accepted values are single, multiple, and any. The default is single. Specifying single starts the counting from the first ancestor node, specifying multiple starts the counting from any ancestor node, and specifying any starts the counting from any node.

  • single–Perform only one count. The current node, if it matches the count expression, or the nearest ancestor that matches the count expression, is counted. The position of the node in document order, relative to its siblings that also match the count parameter, is used as the number to be formatted.

  • multiple–Separately count all nodes that match the count expression and are either the current node or an ancestor of the current node. The position of each node in document order, relative to its siblings that also match the count parameter, is used as one of the numbers to be formatted.

  • any–Perform only one count. The current node, if it matches the count pattern, or its nearest ancestor or preceding node that matches the count pattern, is counted. The position of the node in document order, relative to all other matching nodes that are ancestors or precede the node, is used as the number to be formatted.

Note:

Currently libxslt (1.1.26) does not support the “language” and “letter-value” options for the <xsl:number> element. While SLAX provides a means of encoding these XSLT constructs, they cannot be used in Junos OS.

SLAX Example

The following sample code iterates from 1 through 5. For each integer, the number statement outputs the equivalent uppercase Roman numeral value.

The following sample code provides the string “1234567890” to the number statement, which formats the output in decimal format with a group size of 3 and a comma as a group delimiter.

The following sample code counts all the name elements in the configuration hierarchy stored in the variable $data. The count option combined with the level "multiple" option tracks the count for any name elements under the interface, unit, and address elements.

The format option (1.A.a) includes a start string, which is an open parenthesis, and an end string, which is a close parenthesis and a space character. The number tokens are “1”, “A”, and “a”, which define the formatting of the numbers as decimal format, uppercase alphabetic numbering, and lowercase alphabetic numbering, respectively. The token separator is a period, which is also included in the output.

For the generated numbers displayed in the result tree, the decimal number in parentheses is associated with a particular interface. For each interface, the uppercase letter is associated with each logical unit name, and any lowercase letter is associated with the address name element for that logical unit, which is the IP address.

Release Information

Statement introduced in version 1.1 of the SLAX language, which is supported in Junos OS Release 12.2 and later releases.