Required Boilerplate for Commit Scripts
When you write commit scripts, you use Extensible Stylesheet
Language Transformations (XSLT) or Stylesheet Language Alternative
Syntax (SLAX) tools provided with the Junos OS. These tools include
basic boilerplate that you must include in all commit scripts, optional
extension functions that accomplish scripting tasks more easily, and
named templates that make commit scripts easier to read and write,
which you import from a file called junos.xsl. For more information about the extension functions and templates,
see Junos Extension Functions in the jcs Namespace.
Commit scripts are based on Junos XML and Junos XML protocol tag elements. Like all XML elements, angle brackets enclose the name of a Junos XML or Junos XML protocol tag element in its opening and closing tags. This is an XML convention, and the brackets are a required part of the complete tag element name. They are not to be confused with the angle brackets used in the documentation to indicate optional parts of Junos OS CLI command strings.
You must include either XSLT or SLAX boilerplate as the starting point for all commit scripts that you create. The XSLT boilerplate follows:
XSLT Boilerplate for Commit Scripts
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="configuration">
<!-- ... Insert your code here ... -->
9 </xsl:template>
10 </xsl:stylesheet>
Line 1 is the Extensible Markup Language (XML) processing instruction (PI). This PI specifies that the code is written in XML using version 1.0. The XML PI, if present, must be the first noncomment token in the script file.
1 <?xml version="1.0"?>
Lines 2 through 6 set the style sheet element and the associated namespaces. Line 2 sets the style sheet version as 1.0. Lines 3 through 6 list all the namespace mappings commonly used in commit 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 all namespace mappings prevents errors if the mappings are used in later versions of the script.
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">
Line 7 is an XSLT import statement. It loads the templates and
variables from the file referenced as ../import/junos.xsl, which ships as part of the Junos OS. The junos.xsl file contains a set of named templates you can call in your scripts.
These named templates are discussed in Junos Named Templates in the jcs Namespace.
7 <xsl:import href="../import/junos.xsl"/>
Line 8 defines a template that matches the <configuration> element, which is the node selected by the <xsl:template
match="/"> template, contained in the junos.xsl import file. The <xsl:template match="configuration"> element allows you to exclude the /configuration/ root
element from all XML Path Language (XPath) expressions in the script
and begin XPath expressions with the top Junos OS hierarchy level.
For more information, see XPath Overview.
8 <xsl:template match="configuration">
Add your code between Lines 8 and 9.
Line 9 closes the template.
9 </xsl:template>
Line 10 closes the style sheet and the commit script.
10 </xsl:stylesheet>
SLAX Boilerplate for Commit Scripts
The corresponding SLAX boilerplate is as follows:
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 configuration {
/*
* Insert your code here
*/
}
Hide Navigation Pane
Show Navigation Pane
Download
SHA1