The JUNOS management process (mgd) generates the output document as the product of its evaluation of the input document, as shown in Figure 7.
Figure 7: 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 software’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-output>
3 <xsl:apply-templates select="commit-script-input/configuration"/>
4 </commit-script-output>
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-output>.
- 2 <commit-script-output>
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.
The following example contains the <xsl:if> programming instruction and the <xnm:warning> element. The logical result of both templates is:
<commit-script-output> <!- - 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 router.</message>
</xnm:warning>
</xsl:if> <!- - end of "configuration" template - ->
</commit-script-output> <!- - 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 a router 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')">