The following sections explain each of the XSLT elements shown in this manual. The elements are organized alphabetically.
xsl:apply-templates
<xsl:apply-templates select="node-set-expression">
<xsl:with-param name="qualified-name" select="expression">
...
</xsl:with-param>
</xsl:apply-templates>
Apply one or more templates, according to the value of the select attribute. The nodes to which the processor applies templates are selected by the path specified by the select attribute. The <xsl:template> instruction dictates which elements are transformed according to which template. The templates that are applied are passed the parameters specified by the <xsl:with-param> elements within the <xsl:apply-templates> instruction.
select—Selects the nodes to which the processor applies templates. By default, the processor applies templates to the child nodes of the current node.
See Adding a Final then accept Term to a Firewall and Preventing Import of the Full Routing Table.
xsl:call-template, xsl:for-each, xsl:template, xsl:with-param
xsl:call-template
<xsl:call-template name="qualified-name">
<xsl:with-param name="qualified-name" select="expression">
...
</xsl:with-param>
</xsl:call-template>
Call a named template. The <xsl:with-param> elements within the <xsl:call-template> instruction are used to define parameters that are passed to the template.
name—Specifies the name of the called template.
See Requiring and Restricting Configuration Statements, Imposing a Minimum MTU Setting, Warning About a Deprecated Value, and Automatically Configuring Logical Interfaces and IP Addresses.
xsl:apply-templates, xsl:template
xsl:choose
<xsl:choose>
<xsl:when test="boolean-expression">
...
</xsl:when>
<xsl:otherwise>
...
</xsl:otherwise>
</xsl:call-template>
Express multiple conditional tests. The <xsl:choose> instruction contains one or more <xsl:when> elements, each of which tests an XPath expression. If the test evaluates as TRUE, the XSLT processor executes the instructions in the <xsl:when> element. The XSLT processor processes only the instructions contained in the first <xsl:when> element whose test attribute evaluates as TRUE. If none of the <xsl:when> elements’ test attributes evaluate as TRUE, the content of the <xsl:otherwise> element, if there is one, is processed.
See Controlling a Dual Routing Engine Configuration, Preventing Import of the Full Routing Table, and Automatically Configuring Logical Interfaces and IP Addresses.
xsl:if, xsl:otherwise, xsl:when
xsl:comment
<xsl:comment>
...
</xsl:comment>
Generate a comment within the final document. The content within the <xsl:comment> element determines the value of the comment. The content must not contain two hyphens next to each other (- -); this sequence is not allowed in comments.
XSLT files can contain ordinary <!- - ... Insert your comment here ... - -> comments, but these are ignored by the processor. To generate a comment within the final document, use an <xsl:comment> element.
See Adding a Final then accept Term to a Firewall.
xsl:copy-of
<xsl:copy-of select="expression"/>
Create a copy of what is selected by the expression defined in the select attribute. Namespace nodes, child nodes, and attributes of the current node are automatically copied as well.
select—Specifies an expression to select nodes to be copied.
See Requiring and Restricting Configuration Statements.
<xsl:element name="expression"/>
Create an element node in the output document.
name—Specifies the name of the element to be created. The value of the name attribute can be set to an expression that is extracted from the input XML document. To do this, enclose an XML element in curly brackets ({ }), as in <xsl:element name="{$isis-level-1}".
See Creating a Complex Configuration Based on a Simple Interface Configuration.
xsl:for-each
<xsl:for-each select="node-set-expression">
...
</xsl:for-each>
Include a looping mechanism that repeats XSL processing for each instance of identical XML elements. The element nodes are selected by the expression defined by the select attribute. Each of the nodes is then processed by the instructions contained in the <xsl:for-each> instruction.
select—Specifies an expression to select nodes to be processed.
See Requiring and Restricting Configuration Statements, Imposing a Minimum MTU Setting, Limiting the Number of E1 Interfaces, Adding T1 Interfaces to a RIP Group, Configuring Administrative Groups for LSPs, and Controlling a Dual Routing Engine Configuration.
<xsl:if test="boolean-expression">
...
</xsl:if>
Include a conditional construct that causes instructions to be processed if the Boolean expression held in the test attribute evaluates to TRUE.
test—Specifies a Boolean expression.
See Requiring and Restricting Configuration Statements, Limiting the Number of E1 Interfaces, Adding T1 Interfaces to a RIP Group, and Controlling a Dual Routing Engine Configuration.
<xsl:import href="../import/junos.xsl"/>
Import rules from an external style sheet. Provides access to all the declarations and templates within the imported style sheet, and allows you to override them with your own if needed. Any <xsl:import> elements must be the first elements within the style sheet, the first children of the <xsl:stylesheet> document element. The path can be any URI. The ../import/junos.xsl path shown in the syntax is standard for all commit scripts and automation scripts.
Imported rules are overwritten by any subsequent matching rules within the importing style sheet. If more than one style sheet is imported, the style sheets imported last override each previous import where the rules match.
href—Specifies the location of the imported style sheet.
See all examples listed in Commit Script Examples.
<xsl:otherwise>
...
</xsl:otherwise>
Within an <xsl:choose> instruction, include the instructions that are processed if none of the expressions defined in the test attributes of the <xsl:when> elements evaluate as TRUE.
See Controlling a Dual Routing Engine Configuration and Automatically Configuring Logical Interfaces and IP Addresses.
<xsl:param name="qualified-name" select="expression">
...
</xsl:param>
Declare a parameter for a template (if it is within a template) or for the style sheet as a whole (if it is at the top level of the style sheet).
name—Defines the name of the parameter.
select—Defines the default value for the parameter, which is used if the person or client application that executes the script does not explicitly provide a value. The select attribute or the content of the <xsl:param> element can define the default value. Do not specify both a select attribute and some content; we recommend using the select attribute so as not to create a result tree fragment.
See Requiring and Restricting Configuration Statements, Imposing a Minimum MTU Setting, Limiting the Number of E1 Interfaces, Limiting the Number of ATM Virtual Circuits, and Preventing Import of the Full Routing Table.
xsl:template, xsl:variable, xsl:with-param
xsl:stylesheet
<xsl:stylesheet version="1.0">
<xsl:import href="../import/junos.xsl"/>
...
</xsl:stylesheet>
Include the document element for the style sheet. Contains all the top-level elements such as global variable and parameter declarations, import elements, and templates. Any <xsl:import> elements must be the first elements within the style sheet, the first children of the <xsl:stylesheet> document element. The path can be any URI. The ../import/junos.xsl path shown in the syntax is standard for all commit scripts and automation scripts.
version—Specifies the version of XSLT that is being used. The JUNOS software supports XSLT version 1.0.
See all examples listed in Commit Script Examples.
<xsl:template match="pattern" mode="qualified-name" name="qualified-name">
<xsl:param name="qualified-name" select="expression">
...
</xsl:param>
...
</xsl:stylesheet>
Declare a template that contains rules to apply when a specified node is matched. The match attribute associates the template with an XML element. The match attribute can also be used to define a template for a whole branch of the XML document For example, match="/" matches the whole document.
When templates are applied to a node set using the <xsl:apply-templates> instruction, they might be applied in a particular mode; the mode attribute in the <xsl:template> instruction indicates the mode in which a template needs to be applied for the template to be used. If templates are applied in the specified mode, the match attribute is used to determine whether the template can be used with the particular node.
You can pass templates parameters by using the <xsl:with-param> element. To receive a parameter, the template must contain an <xsl:param> element that declares a parameter of that name. These parameters are listed before the body of the template, which is used to process the node and create a result.
match—Applies the template to nodes by specifying a pattern against which nodes are matched.
mode—Indicates the mode in which a template needs to be applied for the template to be used.
name—Calls the template by name.
See all examples listed in Commit Script Examples.
xsl:apply-templates, xsl:call-template
xsl:text
<xsl:text>
...
</xsl:text>
Insert literal text in the output.
See Requiring and Restricting Configuration Statements, Imposing a Minimum MTU Setting, Limiting the Number of E1 Interfaces, Controlling IS-IS and MPLS Interfaces, and Adding a Final then accept Term to a Firewall.
xsl:value-of
<xsl:value-of select="string-expression"/>
Extract data from the XML structure. The select attribute specifies the expression that is evaluated. In the string expression, use @ to access attributes of elements. Use “ .” to access the contents of the element itself. If the result is a node set, the <xsl:value-of> instruction adds the string value of the first node in that node set; none of the structure of the node is preserved. To preserve the structure of the node, you must use the <xsl:copy-of> instruction instead.
select—Specifies the expression that is evaluated.
See Imposing a Minimum MTU Setting, Limiting the Number of E1 Interfaces, Controlling IS-IS and MPLS Interfaces, Configuring Administrative Groups for LSPs, and Automatically Configuring Logical Interfaces and IP Addresses.
<xsl:variable name="qualified-name" select="expression">
...
</xsl:variable>
Declare a local or global variable. If the <xsl:variable> instruction appears at the top level of the style sheet as a child of the <xsl:stylesheet> document element, it is a global variable with a scope covering the entire style sheet. Otherwise, it is a local variable with a scope of its following siblings and their descendants.
name—Specifies the name of the variable. After declaration, the variable can be referred to within XPath expressions using this name, prefixed with the $ character.
select—Determines the value of the variable. The value of the variable is determined either by the select attribute or by the contents of the <xsl:variable> element. Do not specify both a select attribute and some content; we recommend using the select attribute so as not to create a result tree fragment.
See Limiting the Number of E1 Interfaces, Limiting the Number of ATM Virtual Circuits, Configuring Administrative Groups for LSPs, and Automatically Configuring Logical Interfaces and IP Addresses.
<xsl:when test="boolean-expression">
...
</xsl:when>
Within an <xsl:choose> instruction, specify a set of processing that occurs when the expression specified in the test attribute evaluates as TRUE. The XSLT processor processes only the instructions contained in the first <xsl:when> element whose test attribute evaluates as TRUE. If none of the <xsl:when> elements’ test attributes evaluate as TRUE, the content of the <xsl:otherwise> element, if there is one, is processed.
test—Specifies a Boolean expression.
See Controlling a Dual Routing Engine Configuration, Preventing Import of the Full Routing Table, and Automatically Configuring Logical Interfaces and IP Addresses.
xsl:choose, xsl:if, xsl:otherwise
xsl:with-param
<xsl:with-param name="qualified-name" select="expression">
...
</xsl:with-param>
Specify the value of a parameter to be passed into a template. It can be used when applying templates with the <xsl:apply-templates> instruction or calling templates with the <xsl:call-template> instruction.
name—Specifies the name of the parameter for which the value is being passed.
select—Determines the value of the parameter. The value of the parameter is determined either by the select attribute or by the contents of the <xsl:with-param> element. Do not specify both a select attribute and some content. We recommend using the select attribute to set the parameter so as to prevent the parameter from being passed a result tree fragment as its value.
See Controlling a Dual Routing Engine Configuration, Preventing Import of the Full Routing Table, and Automatically Configuring Logical Interfaces and IP Addresses.
xsl:apply-templates, xsl:call-template, xsl:param