Variables are all declared using the var statement. Variable names are always preceded by a dollar sign:
var $example-string = "Example";

The data type of the variable is automatically determined based on the assigned value. Here are examples of how to declare variables in each of the different data types:
  • string: var $example-string = "Example";
  • number: var $example-number = 15;
  • boolean: var $example-boolean = ( 15 == 15);
  • result tree fragment:
    var $example-rtf = {
         <system> {
             <host-name> "R1";
         }
    }
  • node-set: var $example-node-set = jcs:invoke("get-interface-information");
It is advisable to follow these rules when naming variables, parameters, elements and templates to stay compatible with future Junos script functionality

version 1.0;

ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";

import "../import/junos.xsl";

/* This is a Global Variable */
var $first-string = "Hello World!";

match / {
    <op-script-results> {
        /* This is a variable with template scope */
        var $second-string = "Goodbye World!";
        /* Output both variables to the console */
        <output> $first-string;
        <output> $second-string;
    }
}