[Contents] [Prev] [Next] [Index] [Report an Error]

Boilerplate for Automation Scripts

This section contains basic XSLT and SLAX script boilerplate for automation scripts. You must include either XSLT or SLAX boilerplate as the starting point for all automation scripts that you create. The XSLT boilerplate is followed by line-by-line comments.

XSLT Syntax

1    <?xml version="1.0" standalone="yes"?>
2    <xsl:stylesheet version="1.0"
3        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4        xmlns:junos="http://xml.juniper.net/junos/*/junos"
5        xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm"
6        xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0">

7        <xsl:import href="../import/junos.xsl"/>

8        <xsl:template match="/">
9            <op-script-results>

                <!- - ... insert your code here ... - ->

10            </op-script-results>
11        </xsl:template>

        <!- - ... insert additional template definitions here ... - ->

12    </xsl:stylesheet>

Line 1 is the Extensible Markup Language (XML) processing instruction (PI), which marks this file as XML and specifies the version of XML as 1.0. The XML PI, if present, must be the first non-comment token in the script file.

1    <?xml version="1.0"?>

Line 2 opens the style sheet and specifies the XSLT version as 1.0.

2    <xsl:stylesheet version="1.0"

Lines 3 through 6 list all the namespace mappings commonly used in automation scripts. Not all of these prefixes are used in this example, but it is not an error to list namespace mappings that are not referenced. Listing them all prevents errors if the namespace mappings are used in later versions of the script.

3        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4        xmlns:junos="http://xml.juniper.net/junos/*/junos"
5        xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm"
6        xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0">

Line 7 is an XSLT import statement. It loads the templates and variables from the file ../import/junos.xsl, which ships as part of the JUNOS software (in the file /usr/libdata/cscript/import/junos.xsl). The junos.xsl file contains a set of named templates you can call in your scripts. These named templates are discussed in Importing the junos.xsl File.

7        <xsl:import href="../import/junos.xsl"/> 

Line 8 defines a template that matches the </> element. The <xsl:template match="/"> element is the root element and represents the top level of the XML hierarchy. All XML Path Language (XPath) expressions in the script must start at the top level. This allows the script to access all possible JUNOS XML and JUNOScript Remote Procedure Calls (RPCs). For more information, see XPath.

8        <xsl:template match="/"> 

After the <xsl:template match="/"> tag element, the <op-script-results> and </op-script-results> container tags must be the top-level child tags, as shown in Lines 9 and 10.

9            <op-script-results>
                <!- - ... insert your code here ... - ->
10            </op-script-results>

Line 11 closes the template.

11        </xsl:template> 

After Line 11, you can define additional XSLT templates that are called from within the <xsl:template match="/"> template.

<!- - ... insert additional template definitions here ... - ->

Line 12 closes the style sheet and the automation script.

12    </xsl:stylesheet>

SLAX Syntax

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

match / {
    <op-script-results>
        /*
            * Insert your code here.
        */
}

[Contents] [Prev] [Next] [Index] [Report an Error]