Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Navigation
 

Related Documentation

 

Junos Script Automation: Named Templates in the jcs Namespace Overview

Junos OS provides several named templates to make scripting tasks easier in commit, op, and event scripts. The named templates reside in the junos.xsl import file, which is included with the standard Junos OS installation available on all switches, routers, and security devices running Junos OS.

The Junos OS named templates are defined in the namespace with the associated Uniform Resource Identifier (URI) http://xml.juniper.net/junos/commit-scripts/1.0 . The templates use the jcs: prefix to avoid conflicting with standard XSLT templates or user–defined templates of the same name in a script. To use the Junos named templates in a script, you must include the namespace URI in your style sheet declaration. Map the jcs prefix to the URI by including the xmlns:jcs attribute in the opening <xsl:stylesheet> tag element for XSLT scripts or by including the ns jcs statement in SLAX scripts. You must also import the junos.xsl file into the script by including the <xsl:import/> tag element in XSLT scripts or the import statement in SLAX scripts and specifying the junos.xsl file location.

To call a named template in a script, include the <xsl:call-template name="template-name"> element for XSLT scripts or the call statement for SLAX scripts and pass along any required or optional parameters. Template parameters are assigned by name and can appear in any order. This differs from functions where the arguments must be passed into the function in the precise order specified by the function definition.

The following example imports the junos.xsl file into a script and maps the jcs prefix to the namespace identified by the URI http://xml.juniper.net/junos/commit-scripts/1.0. The script demonstrates a call to the jcs:edit-path template.

XSLT Syntax

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
             xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0">
    <xsl:import href="../import/junos.xsl"/>
...
<xsl:for-each select="interfaces/interface[starts-with(name, 'so-')]"> <xnm:warning> <xsl:call-template name="jcs:edit-path"/> <message>interface configured</message> </xnm:warning> </xsl:for-each> ...
</xsl: stylesheet>

SLAX Syntax

version 1.0;
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
import "../import/junos.xsl"; ...
for-each ( interfaces/interface[starts-with(name,'so-') ) { <xnm:warning> { call jcs:edit-path(); <message> “interface configured”; } } ...

For more information about attributes and tag elements to include in your scripts, see Required Boilerplate for Commit Scripts, Required Boilerplate for Op Scripts, and Required Boilerplate for Event Scripts.

 

Related Documentation

 

Published: 2013-07-26

 

Related Documentation

 

Published: 2013-07-26