In the corresponding commit script, you include one or more XSLT or SLAX programming instructions that inspect the configuration for the apply-macro statement at a specified hierarchy level. Optionally, you can use the data/name expression to select a parameter in the apply-macro statement:
- <xsl:for-each select="xpath-expression/apply-macro[data/name = 'parameter-name']">
For example, the following XSLT programming instruction selects every apply-macro statement that contains the color parameter and that appears at the [edit protocols mpls] hierarchy level:
- <xsl:for-each select="protocols/mpls/apply-macro[data/name
= 'color']">
In SLAX, the syntax looks like this:
- for-each (protocols/mpls/apply-macro[data/name = 'color'])
When expanding macros, a particularly useful programming instruction is the <xsl:value-of> instruction. This instruction selects a parameter value and uses it to build option values for JUNOS statements. For example, the following instruction concatenates the value of the $color variable, the text -lsp-, and the current context node (represented by “ .” ) to build a name for an LSP.
<label-switched-path>
<name>
<xsl:value-of select="concat($color, '-lsp-', .)"/>
</name>
</label-switched-path>
In SLAX, the syntax uses the underscore (_) to concatenate values:
<label-switched-path> {
<name> $color _ '-lsp-' _ .;
Now that you have provided the script with instructions to find the necessary data, you can provide content for a transient change that uses the data to construct a standard JUNOS configuration.
The following transient change creates an administration group and adds the label-switched-path statement to the configuration. The label-switched path is assigned a name that concatenates the value of the $color variable, the text -lsp-, and the currently selected IP address represented by the “ .” . The transient change also adds the to statement and assigns the currently selected IP address. Finally, the transient change adds the admin-group include-any statement and assigns the value of the $color variable.
<transient-change>
<protocols>
<mpls>
<admin-groups>
<name><xsl:value-of select="$color"/></name>
<group-value><xsl:value-of select="$group-value"/></group-value>
</admin-groups>
<xsl:for-each select="data[not(value)]/name">
<label-switched-path>
<name><xsl:value-of select="concat($color, '-lsp-', .)"/></name>
<to><xsl:value-of select="."/></to>
<admin-group>
<include-any><xsl:value-of select="$color"/></include-any>
</admin-group>
</label-switched-path>
</xsl:for-each>
</mpls>
</protocols>
</transient-change>
In SLAX, the syntax looks like this:
<transient-change> {
<protocols> {
<mpls> {
<admin-groups> {
<name> $color;
<group-value> $group-value;
}
for-each (data[not(value)]/name) {
<label-switched-path> {
<name> $color _ '-lsp-' _ .;
<to> .;
<admin-group> {
<include-any> $color;
}
}
}
}
}
}
![]() |
Note: The example shown here is partial. For a full example, see Example: Creating Custom Configuration Syntax with Macros. |
After committing the configuration, the script runs, and the resulting full configuration looks like this:
protocols {
mpls {
label-switched-path blue-lsp-10.1.1.1 {
to 10.1.1.1;
admin-group include-any blue;
}
label-switched-path blue-lsp-10.2.2.2 {
to 10.2.2.2;
admin-group include-any blue;
}
label-switched-path blue-lsp-10.3.3.3 {
to 10.3.3.3;
admin-group include-any blue;
}
label-switched-path blue-lsp-10.4.4.4 {
to 10.4.4.4;
admin-group include-any blue;
}
}
}
The previous example demonstrates how you can use a simplified custom syntax to configure label-switched paths (LSPs). If your network design requires a large number of LSPs to be configured, using a commit script macro can save time, ensure consistency, and prevent configuration errors.