Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

header-navigation
keyboard_arrow_up
close
keyboard_arrow_left
Automation Scripting User Guide
Table of Contents Expand all
list Table of Contents
file_download PDF
{ "lLangCode": "en", "lName": "English", "lCountryCode": "us", "transcode": "en_US" }
English
keyboard_arrow_right

xsl:template match="/" Template

date_range 13-Jan-21

Syntax

content_copy zoom_out_map
<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 OutputCommit 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:

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

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

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

content_copy zoom_out_map
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:

content_copy zoom_out_map
<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:

content_copy zoom_out_map
<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:

content_copy zoom_out_map
<xsl:if test="starts-with(commit-script-input/configuration/system/host-name, 'atlanta')">

You can write this:

content_copy zoom_out_map
<xsl:if test="starts-with(system/host-name, 'atlanta')">
footer-navigation