Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

How to Use the SLAX Processor (slaxproc)

The SLAX processor (slaxproc) is a command-line tool that can validate SLAX script syntax, convert between SLAX and XSLT formats, and format or run SLAX scripts. The slaxproc modes define what function the processor performs. The following sections outlines commonly used modes. For a complete list of the slaxproc modes, see Understanding the SLAX Processor (slaxproc).

Validating SLAX Script Syntax

The SLAX processor provides an option to check the syntax of a SLAX script.

  • To check the syntax of a SLAX script, issue the slaxproc command with the --check or -c mode option and the script filename.

If the script syntax is correct, the SLAX processor issues a "script check succeeds" message. Otherwise, the processor issues a list of error messages detected during script parsing. Fix any indicated errors, and repeat the check.

Converting Scripts Between XSLT and SLAX Formats

The SLAX processor supports converting scripts between SLAX and XSLT formats. When you convert a script, you have the option to reference the file arguments positionally or use the command-line file options, --input or -i and --output or -o, to specify the original input script and the converted output script, respectively. If you use the command-line file options, the files can be referenced in any order on the command line, and the file options can be interspersed among other command-line options.

If you do not provide an argument specifying an input file or an output file, standard input or standard output is used. When using standard input, press Ctrl+d to signal the end-of-file.

To convert a SLAX script to XSLT, issue the slaxproc command with the --slax-to-xslt or -x mode option. To reference the files positionally, specify the input SLAX file as the first argument and the desired output path and filename of the converted XSLT script as the second argument. To reference the files using command-line file options, include the file options in any order. For example:

To convert an XSLT script to SLAX, issue the slaxproc command with the --xslt-to-slax or -s mode option. To reference the files positionally, specify the input XSLT file as the first argument and the desired output path and filename of the converted SLAX script as the second argument. To reference the files using command-line file options, include the file options in any order.

Optionally, when converting a script from XSLT to SLAX, include the --write-version or -w option to specify the SLAX version of the converted script. Acceptable values are 1.0, 1.1, and 1.2. The default version is the latest SLAX version. Use the -p option for partial input when you do not require the SLAX script boilerplate in the output.

The following example converts the XSLT script script1.xsl to the SLAX script script1.slax. The SLAX script will include the statement "version 1.0;" as the first line of the script.

The slaxproc --xslt-to-slax mode with the -p option is useful for quickly converting Junos OS hierarchies from XML format into SLAX. The following example provides the Junos OS [edit policy-options] hierarchy in XML format as input to the SLAX processor. The -p option indicates partial script input as opposed to a full script.

The SLAX processor returns the SLAX formatting for the hierarchy.

Running SLAX Scripts

The SLAX processor supports executing SLAX scripts from the command line. This is the default slaxproc mode. To explicitly use this mode, issue the slaxproc command with the --run or -r command-line mode option.

When you execute a script, you have the option to reference the file arguments positionally or use the command-line file options, --name or -n, --input or -i, and --output or -o, to specify the SLAX script file, and the input and output files, respectively. If you use the command-line file options, the files can be referenced in any order on the command line, and the file options can be interspersed among other command-line options.

If no input file is required, use the -E option to indicate an empty input document. Additionally, if the input or output argument has the value "‑", standard input or standard output is used. When using standard input, press Ctrl+d to signal the end-of-file.

The syntax for executing a script is:

To execute a script using the slaxproc command-line tool:

  1. Create a script using your favorite editor.
  2. (Optional) Check the script syntax by invoking the processor with the --check or -c mode option, and fix any indicated errors.
  3. Execute the script and provide the required input and output files as well as any desired slaxproc options.

    You can reference files positionally or use the command-line file options.

    • To execute a script named script1.slax using input.xml as the input document and output.xml as the output document, issue either of the following commands. The two commands are identical in execution.

    • To execute a script that requires no input file, include the -E option to indicate an empty input document. For example:

    • To execute a script and use standard input as the input document, issue the slaxproc command with no input file argument. At the prompt, enter the input and press Ctrl+d to signal the end-of-file. For example:

Formatting SLAX Scripts

The SLAX processor provides the option to format a script to correct the indentation and spacing to the preferred style. When you format a script, you have the option to reference the file arguments positionally or use the command-line file options, --input or -i and --output or -o, to specify the unformatted input file and the formatted output file, respectively. If you use the command-line file options, the files can be referenced in any order on the command line.

To format a SLAX script, issue the slaxproc command with the --format or -F mode option. To reference the files positionally, specify the unformatted SLAX script as the first argument and the desired output path and filename of the formatted SLAX script as the second argument. To reference the files using command-line file options, include the file options in any order. For example:

Given the following unformatted SLAX script as input:

the SLAX processor outputs the following formatted SLAX script: