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

Boilerplate for Commit Scripts

This section contains basic XSLT and SLAX script boilerplate for commit scripts. You must include either XSLT or SLAX boilerplate as the starting point for all commit scripts that you create. The following example shows the XSLT boilerplate:

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="configuration">
         <!- - ... insert your code here ... - ->
9        </xsl:template>

10   </xsl:stylesheet>

The following example shows the corresponding SLAX code:

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 configuration {
    /*
        * Insert your code here.
    */
}

The following is a line-by-line description of the XSLT boilerplate:

1<?xml version="1.0"?>

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.

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

Lines 2 through 6 set the stylesheet 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 them all prevents errors if the namespace mappings are used in later versions of the script.

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

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 . 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.

8        <xsl:template match="configuration"> 

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 hierarchy level. For more information, see XPath.

The commit script code is added between lines 8 and 9.

9        </xsl:template> 

Line 9 closes the template.

10    </xsl:stylesheet>

Line 10 closes the style sheet and the commit script.


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