Supported Platforms
Converting Scripts Between SLAX and XSLT
SLAX is a C-like alternative syntax to XSLT and can be viewed as a preprocessor for XSLT. Before Junos OS invokes the XSLT processor, the software converts any SLAX constructs in the script (such as if/else if/else) to equivalent XSLT constructs (such as <xsl:choose> and <xsl:if>). For more information about SLAX, see SLAX Overview.
You can use the request system scripts convert operational mode command to convert a script or partial script input written in SLAX or XSLT into the alternate language. Users familiar with C and PERL can convert existing XSLT scripts to SLAX to more easily read and maintain the scripts. In addition, converting a script and studying the results facilitates learning the differences between the two languages.
The following sections explain how to convert a script from one language to the other:
Converting a Script from SLAX to XSLT
To convert a SLAX script to XSLT, issue the request system scripts convert slax-to-xslt operational mode command, and specify the source file, the destination directory, and, optionally, a destination file. The source script is the basis for the new script. The source script is not overwritten by the new script.
The command syntax is:
Starting with Junos OS Release 12.2, you can include the partial option to convert partial script input.
The following three examples convert a script from SLAX to XSLT using a source and destination directory relevant to the default storage location for the type of script being converted:
user@host> request system scripts convert slax-to-xslt
source /var/db/scripts/op/script1.slax destination /var/db/scripts/op/script1.xsl
conversion complete
user@host> request system scripts convert slax-to-xslt
source /var/db/scripts/event/script1.slax destination /var/db/scripts/event/script1.xsl
conversion complete
user@host> request system scripts convert slax-to-xslt
source /var/db/scripts/commit/script1.slax destination /var/db/scripts/commit/script1.xsl
conversion complete
When you issue the slax-to-xslt conversion command,
the script1.slax
file remains unchanged
in the source directory, and a new script called script1.xsl
is added to the destination directory.
user@host> file list /var/db/scripts/op
script1.slax
script1.xsl
If you specify only the destination directory and do not specify
a destination filename, the generated filename is SLAX-Conversion-Temp
or slax-temp
depending on the Junos OS release, with a randomly generated, five-character,
alpha-numeric extension.
user@host> request system scripts convert slax-to-xslt
source /var/db/scripts/op/script1.slax destination /var/db/scripts/op/
conversion complete
user@host> file list /var/db/scripts/op
slax-temp.SlhIr
script1.slax
Converting a Script from XSLT to SLAX
To convert an XSLT script to SLAX, issue the request system scripts convert xslt-to-slax operational mode command, and specify the source file, the destination directory, and, optionally, a destination file. The source script is the basis for the new script. The source script is not overwritten by the new script.
The command syntax is:
To convert partial script input, include the partial option in the command. The version option specifies the SLAX version that will be listed in the version statement of the generated script. Specify the version as either 1.0 or 1.1. The default is 1.1. The partial and version options are supported starting with Junos OS Release 12.2.
The following three examples convert a script from XSLT to SLAX using a source and destination directory relevant to the default storage location for the type of script being converted:
user@host> request system scripts convert xslt-to-slax
source /var/db/scripts/op/script1.xsl destination /var/db/scripts/op/script1.slax
version 1.0
conversion complete
user@host> request system scripts convert xslt-to-slax
source /var/db/scripts/event/script1.xsl destination /var/db/scripts/event/script1.slax
version 1.0
conversion complete
user@host> request system scripts convert xslt-to-slax
source /var/db/scripts/commit/script1.xsl destination /var/db/scripts/commit/script1.slax
version 1.0
conversion complete
When you issue the xslt-to-slax conversion
command, the script1.xsl
file remains
unchanged in the source directory, and a new script called script1.slax
is added to the destination directory.
user@host> file list /var/db/scripts/op
script1.slax
script1.xsl
The SLAX script boilerplate lists the specified SLAX version. In this example, the version is 1.0.
user@host> file show /var/db/scripts/op/script1.slax
/* Machine Crafted with Care (tm) by slaxWriter */
version 1.0;
...
If you specify only the destination directory and do not specify
a destination filename, the generated filename is SLAX-Conversion-Temp
or slax-temp
depending on the Junos OS release, with a randomly generated,
five-character, alpha-numeric extension.
user@host> request system scripts convert xslt-to-slax
source /var/db/scripts/op/script1.xsl destination /var/db/scripts/op/
conversion complete
user@host> file list /var/db/scripts/op
slax-temp.Vosnd
script1.xsl