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


Boilerplate for Commit Scripts

This section contains basic XSLT script boilerplate for commit scripts. You must include this boilerplate as the starting point for all commit scripts that you create. This boilerplate is followed by line-by-line comments.

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), which marks this file as XML and specifies the version of XML as 1.0. The XML PI, if present, must be the first noncomment 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 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.

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

8        <xsl:template match="configuration"> 

Line 9 closes the template.

9        </xsl:template> 

Line 10 closes the style sheet and the commit script.

10    </xsl:stylesheet>

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