Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

header-navigation
keyboard_arrow_up
close
keyboard_arrow_left
Automation Scripting User Guide
Table of Contents Expand all
list Table of Contents
file_download PDF
{ "lLangCode": "en", "lName": "English", "lCountryCode": "us", "transcode": "en_US" }
English
keyboard_arrow_right

SLAX Elements as Function Arguments

date_range 29-Nov-23

Starting with version 1.2 of the SLAX language, which is supported in Junos OS Release 14.2 and later releases, you can use SLAX elements directly as arguments for both functions and templates. Function arguments can either be a single element or a block of SLAX code, placed inside braces as shown in the following example:

content_copy zoom_out_map
var $a = my:function(<elt>,<max> 15);
content_copy zoom_out_map
var $b = my:test ({
    <min> 5;
    <max> 15;
    if ($step) {
        <step> $step;
    }
});
content_copy zoom_out_map
var $c = my:write(<content> {
    <document> "total.txt";
    <size> $file/size;
    if (node[@type == "full"]) {
        <full>;
    }
});

For templates, you still need to include the argument name, but the value can be inline. For example:

content_copy zoom_out_map
call my:valid($name = <name> $input, $object = {
    <min> $min;
    <max> $max;
});

The Main Template

Starting with version 1.2 of the SLAX language, which is supported in Junos OS Release 14.2 and later releases, the main template is introduced in SLAX. The main template enables you to process the input XML document and provide the top-level element for the output hierarchy. The main template is equivalent to using match / but slightly more convenient.

You can use the main statement to match the top of the input data hierarchy and create the top-level tag of the output hierarchy. You can use the statement in two forms: with or without the output tag. When you omit the output element, main is just followed by a block of statements within a set of braces, as shown in the following example:

content_copy zoom_out_map
main {
    <top> {
        <answer> 42;
    }
}

The main template can also be used with a top-level output element following the main token, as shown in the following example:

content_copy zoom_out_map
main <top> {
    <answer> 42;
}

Both of the preceding examples are equivalent to the following XSLT version:

content_copy zoom_out_map
<xsl:template match="/">
    <top>
        <answer>42</answer>
    </top>
</xsl:template>
footer-navigation