Variables are usable only within a limited scope. A scope is the code hierarchy in which a variable is declared. Each variable can be used within its own scope, as well as in other specific scopes that also fall within the declared scope. 

Following are the main types of scopes for variables:

Global variable: refers to any variable declared outside of all templates. Global variables can be referenced anywhere within the script.

Template variable: refers to variables defined within templates, such as the main template, and have a local scope and are scoped by the containing scope.

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;
    }
}