Supported Platforms
Related Documentation
- ACX, EX, M, MX, SRX, T Series
- Junos Named Templates in the jcs Namespace Summary
- Junos Script Automation: Understanding Extension Functions in the jcs and slax Namespaces
- ACX, EX, M, MX, PTX, SRX, T Series
- Junos Script Automation: Named Templates in the jcs Namespace Overview
- Junos Script Automation: Global Parameters and Variables in the junos.xsl File
- apply-templates
- xsl:apply-templates
- xsl:template
xsl:template match="/" Template
Syntax
<xsl:template match="/">
Description
The <xsl:template match="/"> template is an unnamed template in the junos.xsl
file that allows you to use shortened XPath expressions in commit scripts. You must import the junos.xsl
file to use this template. However, because
this template is not in the jcs namespace,
you do not need to map to the jcs namespace
in your style sheet declaration in order to use this template.
Junos OS provides XML-formatted input to a script. Commit script input consists of an XML representation of the post-inheritance candidate configuration file. When you execute a script, the Junos OS management process (mgd) generates an XML-formatted output document as the product of its evaluation of the input document, as shown in Figure 1.
Figure 1: Commit Script Input and Output

Generally, an XSLT engine uses recursion to evaluate the entire input document. However, the <xsl:apply-templates> instruction allows you to limit the scope of the evaluation so that the management process (the Junos OS’s XSLT engine) must evaluate only a subset of the input document.
The <xsl:template match="/"> template is an unnamed template that uses the <xsl:apply-templates> instruction to specify the contents of the input document’s <configuration> element as the only node to be evaluated in the generation of the output document.
The <xsl:template match="/"> template contains the following tags:
1 <xsl:template match="/">
2 <commit-script-results>
3 <xsl:apply-templates select="commit-script-input/configuration"/>
4 </commit-script-results>
5 </xsl:template>
Line 1 matches the root node of the input document. When the management process sees the root node of the input document, this template is applied.
1 <xsl:template match="/">
Line 2 designates the root, top-level tag of the output document. Thus, Line 2 specifies that the evaluation of the input document results in an output document whose top-level tag is <commit-script-results>.
2 <commit-script-results>
Line 3 limits the scope of the evaluation of the input document to the contents of the <configuration> element, which is a child of the <commit-script-input> element.
3 <xsl:apply-templates select="commit-script-input/configuration"/>
Lines 4 and 5 are closing tags.
You do not need to explicitly include the <xsl:template match="/"> template in your scripts because this template
is included in the import file junos.xsl
.
When the <xsl:template match="/"> template executes the <xsl:apply-templates> instruction, the script jumps to a template that matches the <configuration> tag. This template, <xsl:template match="configuration">, is part of the commit script boilerplate that you must include in all of your commit scripts:
<xsl:template match="configuration">
<!-- ... insert your code here ... -->
</xsl:template>
Thus, the import file junos.xsl
contains a template that points to a template explicitly referenced
in your script.
Usage Examples
The following example contains the <xsl:if> programming instruction and the <xnm:warning> element. The logical result of both templates is:
<commit-script-results> <!-- from template in junos.xsl import file -->
<xsl:if test="not(system/host-name)"> <!-- from "configuration" template -->
<xnm:warning xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm">
<edit-path>[edit system]</edit-path>
<statement>host-name</statement>
<message>Missing a hostname for this device.</message>
</xnm:warning>
</xsl:if> <!-- end of "configuration" template -->
</commit-script-results> <!-- end of template in junos.xsl import file -->
When you import the junos.xsl
file and explicitly include the <xsl:template match="configuration"> tag in your commit script, the context (dot) moves to the <configuration> node.
This allows you to write all XPath expressions relative to that point.
This technique allows you to simplify the XPath expressions you use
in your commit scripts. For example, instead of writing this, which
matches the device with hostname atlanta:
<xsl:if test="starts-with(commit-script-input/configuration/system/host-name, 'atlanta')">
You can write this:
<xsl:if test="starts-with(system/host-name, 'atlanta')">
Related Documentation
- ACX, EX, M, MX, SRX, T Series
- Junos Named Templates in the jcs Namespace Summary
- Junos Script Automation: Understanding Extension Functions in the jcs and slax Namespaces
- ACX, EX, M, MX, PTX, SRX, T Series
- Junos Script Automation: Named Templates in the jcs Namespace Overview
- Junos Script Automation: Global Parameters and Variables in the junos.xsl File
- apply-templates
- xsl:apply-templates
- xsl:template
Published: 2013-07-26
Supported Platforms
Related Documentation
- ACX, EX, M, MX, SRX, T Series
- Junos Named Templates in the jcs Namespace Summary
- Junos Script Automation: Understanding Extension Functions in the jcs and slax Namespaces
- ACX, EX, M, MX, PTX, SRX, T Series
- Junos Script Automation: Named Templates in the jcs Namespace Overview
- Junos Script Automation: Global Parameters and Variables in the junos.xsl File
- apply-templates
- xsl:apply-templates
- xsl:template