Convert Scripts Between SLAX and XSLT
Convert a complete or partial script written in SLAX or XSLT into the alternate language.
You can write Junos automation scripts in SLAX and XSLT. SLAX is a C-like alternative
syntax to XSLT. You can view SLAX 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 complete or partial script 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.
Convert 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. Specify the source file, the
destination directory, and optionally, a destination file. You can include the
partial option to convert a partial script. The source
script is the basis for the new script and is not overwritten in the conversion
process.
The command syntax is:
user@host> request system scripts convert slax-to-xslt source source-path/filename destination destination-path/<filename> <partial>
The following examples convert a script from SLAX to XSLT using a source and destination directory relevant to the default storage location for that script type:
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 previous 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 you do not specify a destination filename, the device generates a filename. The generated filename is slax-temp or SLAX-Conversion-Temp, depending on the Junos OS release, and 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.Pd88f script1.slax
Convert 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. Specify the source file, the
destination directory, and optionally, a destination file. The source script is
the basis for the new script and is not overwritten in the conversion
process.
The command syntax is:
user@host> request system scripts convert xslt-to-slax source source-path/filename destination destination-path/<filename> <partial> <version version>
To convert a partial script, include the partial option in the command. The
version option specifies the SLAX version that the
generated script lists in its version statement.
The following examples convert a script from XSLT to SLAX using a source and destination directory relevant to the default storage location for that script type:
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.2 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 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 conversion complete
When you issue the previous 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.2. If you do not specify a version, the version defaults to the latest SLAX version available on the device.
user@host> file show /var/db/scripts/op/script1.slax /* Machine Crafted with Care (tm) by slaxWriter */ version 1.2; ...
If you specify only the destination directory, and you do not specify a destination filename, the device generates a filename. The generated filename is slax-temp or SLAX-Conversion-Temp, depending on the Junos OS release, and 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