Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

printf() Function (Python, SLAX, and XSLT)

Namespaces

Python Syntax

SLAX Syntax

XSLT Syntax

Description

Generate formatted output text. The function supports most standard printf formats, in addition to some Junos OS–specific formats. The function returns a formatted string but does not print it on call. To use the following Junos OS modifiers, place the modifier between the percent sign (%) and the conversion specifier.

  • jc—Capitalize the first letter of the associated output string.

  • jh—(SLAX scripts only) Transform large numbers into a human-readable format by applying a divisor of 1024 and adding the appropriate unit suffix (K, M, G, T, and so on). For example, a value of 65536 becomes 64K.

  • jH—(SLAX scripts only) Transform large numbers into a human-readable format by applying a divisor of 1000 and adding the appropriate unit suffix (K, M, G, T, and so on). For example, a value of 65536 becomes 66k.

  • j1—Emit a field only if it changed from the last time the function was called. This assumes that the expression’s format string is unchanged.

  • jt{TAG}—Emit the tag if the associated argument is not empty.

  • j{flag1, flag2, ...}—(SLAX scripts only) When using the %jh or %jH formats, apply one or more additional flags that modify the output.

    • Values:

      • b—Append 'B' (bytes) as the suffix when the value is less than 1000.

      • suffix=string—Append the given suffix after the number and the unit suffix.

      • whole—Round the value to the nearest integer value.

The prefix associated with the namespace URI should be defined in the prefix-to-namespace mapping in the style sheet.

Parameters

expression

Format string containing an arbitrary number of format specifiers and associated arguments to output.

Usage Examples

In the following XSLT example, the j1 operator suppresses printing the interface identifier ge-0/0/0 in the second line of output, because the value has not changed from the first printing. The jc operator capitalizes the output strings up and down. The jt{--} operator does not print the {--} tag in the first line of output, because the associated output argument is an empty string. However, the operator prints the tag in the second line because the associated output is the non-empty string test.

The function produces the following output:

The following SLAX version 1.3 script formats some data values using the %jh and %jH flags for human-readable output.

The script produces the following output:

Release Information

Function introduced in Junos OS Release 7.6.

Support for the slax namespace http://xml.libslax.org/slax added in Junos OS Release 12.2.

Support for Python added in Junos OS Release 16.1R1.

Support for %jh, %jH, and %j{flag} added in SLAX version 1.3.