Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 

xsl:template match="/" Template

 

Syntax

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

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.

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

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.

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:

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:

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:

You can write this: