Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

SLAX Overview

Stylesheet Language Alternative syntaX (SLAX) is a language for writing Junos OS commit scripts, op scripts, event scripts, and SNMP scripts. It is an alternative to Extensible Stylesheet Language Transformations (XSLT). SLAX has a distinct syntax similar to that of C and Perl but the same semantics as XSLT.

Benefits of SLAX and SLAX Scripts

  • SLAX scripts employ a clean, readable syntax that emphasizes XPath expressions and XML content creation.

  • SLAX scripts provide fast configuration database access and XML processing for optimal performance.

  • SLAX scripts can utilize the debugger and profiler tools in the libslax library to help parse, troubleshoot, and analyze the performance of the scripts to ensure the most efficient operation.

SLAX Syntax Advantages

XSLT is a powerful and effective tool for handling Extensible Markup Language (XML) that works well for machine-to-machine communication, but its XML-based syntax is inconvenient for the development of complex programs.

SLAX has a simple syntax that follows the style of C and PERL. It provides a practical and succinct way to code, thus enabling you to create readable, maintainable commit, op, event, and SNMP scripts. SLAX removes XPath expressions and programming instructions from XML elements. XML angle brackets and quotation marks are replaced by parentheses and curly brackets ({ }), which are the familiar delimiters of C and PERL.

The benefits of the SLAX syntax are particularly strong for programmers who are not already accustomed to XSLT, because SLAX enables them to concentrate on the new programming topics introduced by XSLT, rather than concentrating on learning a new syntax. For example, SLAX enables you to:

  • Write more readable scripts

  • Reduce the clutter in your scripts

  • Simplify namespace declarations

  • Define named templates with a syntax resembling a function definition

  • Invoke named templates with a syntax resembling a function call

  • Use curly braces to show containment instead of closing tags

  • Use if, else if, and else statements instead of <xsl:choose> and <xsl:if> elements

  • Put test expressions in parentheses ( )

  • Use the double equal sign (==) to test equality instead of the single equal sign (=)

  • Perform concatenation using the underscore (_) operator, as in PERL, version 6

  • Write text strings using simple quotation marks (" ") instead of the <xsl:text> element

How SLAX Works

SLAX functions as a preprocessor for XSLT. Junos OS internally translates SLAX programming instructions (such as if and else statements) into the equivalent XSLT instructions (such as <xsl:if> and <xsl:choose> elements). After this translation, the XSLT transformation engine—the mgd process—is invoked.

SLAX does not affect the expressiveness of XSLT; it only makes XSLT easier to use. The underlying SLAX constructs are completely native to XSLT. SLAX adds nothing to the XSLT engine. The SLAX parser parses an input document and builds an XML tree identical to the one produced when the XML parser reads an XSLT document.

Figure 1 shows the flow of SLAX script input and output.

Figure 1: SLAX Script Input and Output SLAX Script Input and Output

SLAX Resources

Table 1 outlines additional resources that you can use to learn SLAX and write SLAX scripts.

Table 1: SLAX Resources

Resource

URL

SLAX Manual

http://juniper.github.io/libslax/slax-manual.html

Junos Automation Reference for SLAX 1.0

https://www.juniper.net/documentation/en_US/day-one-books/archive/TW_Junos_Automation_Reference.pdf

Libslax—an open-source implementation of the SLAX language

https://github.com/Juniper/libslax

https://github.com/Juniper/libslax/wiki