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 the Junos OS invokes the XSLT processor, the software converts SLAX constructs (such as if/then/else) to equivalent XSLT constructs (such as <xsl:choose> and <xsl:if>). For more information about SLAX, see SLAX Overview.

Converting scripts manually and studying the results facilitates learning of the differences between the two languages. If you have existing XSLT commit, op, and event scripts, conversion to SLAX allows C and PERL programmers to more easily read and maintain the scripts.

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 and an optional destination file. The source script is the basis for a new script. The source script is not overwritten by the new script. The following three examples show the command using a source and destination directory relevant 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
user@host> request system scripts convert slax-to-xslt source /var/db/scripts/event/script1.slax destination /var/db/scripts/event/script1.xsl
user@host> request system scripts convert slax-to-xslt source /var/db/scripts/commit/script1.slax destination /var/db/scripts/commit/script1.xsl

When you issue this command, the script1.slax file remains unchanged in the source directory and a new script called script1.xsl is added to the destination directory. If you do not specify a filename for the destination file, the file is named SLAX-Conversion-Temp.xxxxx where xxxxx is a randomly generated series of characters.

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 and an optional destination file. The source script is the basis for a new script. The source script is not overwritten by the new script. The following three examples show the command using a source and destination directory relevant 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
user@host> request system scripts convert xslt-to-slax source /var/db/scripts/event/script1.xsl destination /var/db/scripts/event/script1.slax
user@host> request system scripts convert xslt-to-slax source /var/db/scripts/commit/script1.xsl destination /var/db/scripts/commit/script1.slax

When you issue this command, the script1.xsl file remains unchanged in the source directory, and a new script called script1.slax is added to the destination directory. If you do not specify a filename for the destination file, the file is named SLAX-Conversion-Temp.xxxxx where xxxxx is a randomly generated series of characters.

Related Topics