Supported Platforms
number
Syntax
number expression { format numbering-style; grouping-separator character; grouping-size number; }
number { count nodes; format numbering-style; from nodes; grouping-separator character; grouping-size number; level "single" | "multiple" | "any"; }
Release Information
Statement introduced in version 1.1 of the SLAX language, which is supported in Junos OS Release 12.2 and later releases.
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:
Table 1: Numbering Styles for SLAX Statement number, format Option
|
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.
|
![]() | 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 are not usable under 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.
for $i (1 ... 5) { number $i { format "I "; } }
I II III IV V
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.
number "1234567890" { grouping-size 3; grouping-separator ","; format "1"; }
1,234,567,890
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.
var $data := { <interfaces> { <interface> { <name> "ge-0/0/0"; <unit> { <name> "0"; } <unit> { <name> "1"; } } <interface> { <name> "ge-0/1/0"; <unit> { <name> "10"; <family> { <inet>; } } } <interface> { <name> "ge-2/0/2"; <unit> { <name> "0"; <family> { <inet> { <address> { <name> "10.1.1.1/24"; } } } } } } } for-each ($data//name) { number { level "multiple"; count interface|unit|address; format "(1.A.a) "; } expr . _ "\n"; }
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.
(1) ge-0/0/0 (1.A) 0 (1.B) 1 (2) ge-0/1/0 (2.A) 10 (3) ge-2/0/2 (3.A) 0 (3.A.a) 10.1.1.1/24