SLAX Statements Overview
This section lists some commonly used SLAX statements, with brief examples and XSLT equivalents. For a complete list of SLAX statements, see Summary of SLAX Statements.
for-each Statement
The SLAX for-each statement functions like the <xsl:for-each> element. The statement consists of the for-each keyword, the parentheses-delimited expression, and a curly braces-delimited block.
for-each ($inventory/chassis/chassis-module/
chassis-sub-module[part-number == '750-000610']) {
<message> "Down rev PIC in " _ ../name _ ", " _ name _ ": " _ description;
}
The XSLT equivalent is:
<xsl:for-each select="$inventory/chassis/chassis-module/
chassis-sub-module[part-number == '750-000610']">
<message>
<xsl:value-of select="concat('Down rev PIC in ', ../name, ', ', name, ': ',
description)"/>
</message>
</xsl:for-each>
if, else if, and else Statements
SLAX supports if, else if, and else statements. The expressions that appear in parentheses are extended XPath expressions, which support the double equal sign (==) in place of XPath’s single equal sign (=).
if (expression) {
/* If block Statement */
}
else if (expression) {
/* else if block statement */
}
else {
/* else block statement */
}Depending on the presence of the else clause, an if statement is transformed into either an <xsl:if> element or an <xsl:choose> element.
if (starts-with(name, "fe-")) {
if (mtu < 1500) {
/* Select Fast Ethernet interfaces with low MTUs */
}
}
else {
if (mtu > 8096) {
/* Select non-Fast Ethernet interfaces with high MTUs */
}
}The XSLT equivalent is:
<xsl:choose>
<xsl:when select="starts-with(name, 'fe-')">
<xsl:if test="mtu < 1500">
<!-- Select Fast Ethernet interfaces with low MTUs -->
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:if test="mtu > 8096">
<!-- Select non-Fast Ethernet interfaces with high MTUs -->
</xsl:if>
</xsl:otherwise>
</xsl:choose>
match Statement
You specify basic match templates using the match statement, followed by an expression specifying when the template should be allowed and a block of statements enclosed in a set of braces.
match configuration {
<xnm:error> {
<message> "...";
}
}The XSLT equivalent is:
<xsl:template match="configuration">
<xnm:error>
<message> ...</message>
</xnm:error>
</xsl:template>
ns Statement
You specify namespace definitions using the SLAX ns statement. This consists of the ns keyword, a prefix string, an equal sign, and a namespace Uniform Resource Identifier (URI). To define the default namespace, use only the ns keyword and a namespace URI.
ns junos = "http://www.juniper.net/junos/";
The ns statement can appear after the version statement at the beginning of the style sheet or at the beginning of any block.
ns a = "http://example.com/1";
ns "http://example.com/global";
ns b = "http://example.com/2";
match / {
ns c = "http://example.com/3";
<top> {
ns a = "http://example.com/4";
apply-templates commit-script-input/configuration;
}
}
When it appears at the beginning of the style sheet, the ns statement can include either the exclude or extension keyword. The keyword instructs the parser to add the namespace prefix to the exclude-result-prefixes or extension-element-prefixes attribute.
ns exclude foo = "http://example.com/foo";
ns extension jcs = "http://xml.juniper.net/jcs";
The XSLT equivalent is:
<xsl:stylesheet xmlns:foo="http://example.com/foo"
xmlns:jcs="http://xml.juniper.net/jcs"
exclude-result-prefixes="foo"
extension-element-prefixes="jcs">
<!-- ... -->
</xsl:stylesheet>
version Statement
All SLAX style sheets must begin with a version statement, which specifies the version number for the SLAX language. The current version is 1.0. SLAX version 1.0 uses XML version 1.0 and XSLT version 1.1.
version 1.0;
The XSLT equivalen ist:
<xsl:stylesheet version="1.0">
Hide Navigation Pane
Show Navigation Pane
Download
SHA1