- play_arrow Overview
- play_arrow Junos Automation Scripts Overview
- play_arrow Junos XML Management Protocol and Junos XML API Overview
-
- play_arrow Automation Scripting Using SLAX
- play_arrow SLAX Overview
- SLAX Overview
- SLAX Syntax Rules Overview
- SLAX Elements and Element Attributes Overview
- SLAX Elements as Function Arguments
- Understanding SLAX Default Namespaces
- XPath Expressions Overview for SLAX
- SLAX Templates Overview
- SLAX Functions Overview
- SLAX Parameters Overview
- SLAX Variables Overview
- SLAX Statements Overview
- XSLT Elements Without SLAX Equivalents
- SLAX Operators
- play_arrow SLAX Statements
- append
- apply-imports
- apply-templates
- attribute
- attribute-set
- call
- copy-node
- copy-of
- decimal-format
- element
- else
- else if
- expr
- fallback
- for
- for-each
- function
- if
- import
- key
- match
- message
- mode
- mvar
- number
- output-method
- param
- preserve-space
- priority
- processing-instruction
- result
- set
- sort
- strip-space
- template
- terminate
- trace
- uexpr
- use-attribute-sets
- var
- version
- while
- with
- play_arrow The libslax Distribution for Automation Scripting
- libslax Distribution Overview
- libslax Library and Extension Libraries Overview
- Download and Install the libslax Distribution
- libslax Default Extension Libraries: bit, curl, db, os, and xutil
- Understanding the SLAX Processor (slaxproc)
- How to Use the SLAX Processor (slaxproc)
- SLAX Debugger, Profiler, and callflow
-
- play_arrow Automation Scripting Using Python
- play_arrow Python Overview
- Understanding Python Automation Scripts for Junos Devices
- Requirements for Executing Python Automation Scripts on Junos Devices
- Overview of Python Modules on Junos Devices
- How to Use Python Interactive Mode on Devices Running Junos OS
- How to Use the psutil Module to Retrieve Process and System Information on Devices Running Junos OS
- How to Use the Requests Library for Python on Devices Running Junos OS
- IPv6 Support in Python Automation Scripts
- How to Specify the Routing Instance in Python 3 Applications on Devices Running Junos OS Evolved
-
- play_arrow Automation Script Input
- play_arrow Global Parameters in Automation Scripts
-
- play_arrow Extension Functions and Named Templates for Automation Scripts
- play_arrow Extension Functions for Automation Scripting
- play_arrow Extension Functions in the jcs and slax Namespaces
- base64-decode() Function (SLAX)
- base64-encode() Function (SLAX)
- break-lines() Function (SLAX and XSLT)
- close() Function (SLAX and XSLT)
- dampen() Function (Python, SLAX, and XSLT)
- document() Function (SLAX)
- emit_error() Function (Python)
- emit_snmp_attributes Function (Python)
- emit_warning() Function (Python)
- empty() Function (SLAX and XSLT)
- evaluate() Function (SLAX)
- execute() Function (SLAX and XSLT)
- first-of() Function (SLAX and XSLT)
- get-command() Function (SLAX)
- get-hello() Function (SLAX and XSLT)
- get-input() Function (SLAX and XSLT) and get_input() (Python)
- get-protocol() Function (SLAX and XSLT)
- get-secret() Function (SLAX and XSLT) and get_secret() (Python)
- get_snmp_action() Function (Python)
- get_snmp_oid() Function (Python)
- hostname() Function (Python, SLAX, and XSLT)
- invoke() Function (SLAX and XSLT)
- open() Function (SLAX and XSLT)
- output() Function (Python, SLAX, and XSLT)
- parse-ip() Function (SLAX and XSLT) and parse_ip() (Python)
- printf() Function (Python, SLAX, and XSLT)
- progress() Function (Python, SLAX, and XSLT)
- regex() Function (SLAX and XSLT)
- set_routing_instance() Function (Python)
- sleep() Function (SLAX and XSLT)
- split() Function (SLAX and XSLT)
- sysctl() Function (Python, SLAX, and XSLT)
- syslog() Function (Python, SLAX, and XSLT)
- trace() Function (Python, SLAX, and XSLT)
- play_arrow Named Templates for Automation Scripting
- play_arrow Named Templates in the jcs Namespace
-
- play_arrow Manage Automation Scripts
- play_arrow Store and Enable Scripts
- play_arrow Configure a Remote Source for Scripts
- play_arrow Configure the Session Protocol for Scripts
- play_arrow Control Execution of Scripts
- play_arrow Synchronize Scripts Between Routing Engines
- play_arrow Convert Scripts Between SLAX and XSLT
-
- play_arrow Commit Scripts
- play_arrow Commit Scripts Overview
- play_arrow Create and Execute Commit Scripts
- Required Boilerplate for Commit Scripts
- XML Syntax for Common Commit Script Tasks
- Design Considerations for Commit Scripts
- How to Avoid Potential Conflicts When Using Multiple Commit Scripts
- Line-by-Line Explanation of Sample Commit Scripts
- Control the Execution of Commit Scripts During Commit Operations
- Control the Execution of Commit Scripts in the QFabric System
- Configure Checksum Hashes for a Commit Script
- How to Process Large Configurations Against Commit Scripts
- Example: Retrieve the Pre-Inheritance Candidate Configuration in a Commit Script
- play_arrow Generate a Custom Warning, Error, or System Log Message Using Commit Scripts
- Overview of Generating Custom Warning, Error, and System Log Messages
- Generate a Custom Warning, Error, or System Log Message in Commit Scripts
- SLAX and XSLT Commit Script Tag Elements to Use When Generating Messages
- Example: Generate a Custom Warning Message
- Example: Generate a Custom Error Message
- Example: Generate a Custom System Log Message
- play_arrow Generate Persistent or Transient Configuration Changes Using Commit Scripts
- Overview of Generating Persistent or Transient Configuration Changes Using Commit Scripts
- Generate a Persistent or Transient Configuration Change in SLAX and XSLT Commit Scripts
- Generate a Persistent or Transient Configuration Change in Python Commit Scripts
- SLAX and XSLT Commit Script Tag Elements to Use When Generating Persistent and Transient Configuration Changes
- Remove a Persistent or Transient Configuration Change Using Commit Scripts
- Example: Generate Persistent and Transient Configuration Changes Using Commit Scripts
- play_arrow Create Custom Configuration Syntax with Commit Script Macros
- Overview of Creating Custom Configuration Syntax with Commit Script Macros
- Create Custom Configuration Syntax with Commit Script Macros
- Create a Commit Script Macro to Read the Custom Syntax and Generate Related Configuration Statements
- Example: Creating Custom Configuration Syntax with Commit Script Macros
- play_arrow Commit Script Examples
- Example: Adding a Final then accept Term to a Firewall
- Example: Adding T1 Interfaces to a RIP Group
- Example: Assign a Classifier Using a Commit Script
- Example: Automatically Configure Logical Interfaces and IP Addresses
- Example: Configure Administrative Groups for LSPs
- Example: Configure a Default Encapsulation Type
- Example: Configure Dual Routing Engines
- Example: Configure an Interior Gateway Protocol on an Interface
- Example: Control IS-IS and MPLS Interfaces
- Example: Control LDP Configuration
- Example: Create a Complex Configuration Based on a Simple Interface Configuration
- Example: Impose a Minimum MTU Setting
- Example: Limit the Number of ATM Virtual Circuits
- Example: Limit the Number of E1 Interfaces
- Example: Load a Base Configuration
- Example: Prepend a Global Policy
- Example: Prevent Import of the Full Routing Table
- Example: Require Internal Clocking on T1 Interfaces
- Example: Require and Restrict Configuration Statements
- play_arrow Junos XML and XSLT Tag Elements Used in Commit Scripts
- play_arrow Troubleshoot Commit Scripts
-
- play_arrow Op Scripts
- play_arrow Op Scripts Overview
- play_arrow Create and Execute Op Scripts
- Required Boilerplate for Op Scripts
- Map Operational Mode Commands and Output Fields to Junos XML Notation
- How to Use RPCs and Operational Mode Commands in Op Scripts
- Declare and Use Command-Line Arguments in Op Scripts
- Configure Help Text for Op Scripts
- Define Operational Mode Commands to Allow in an Op Script
- Enable an Op Script and Define a Script Alias
- Configure Checksum Hashes for an Op Script
- Execute an Op Script on the Local Device
- Execute an Op Script from a Remote Site
- Disable an Op Script
- play_arrow Op Script Examples
- Change the Configuration Using SLAX and XSLT Scripts
- Example: Change the Configuration Using SLAX and XSLT Op Scripts
- Example: Change the Configuration Using Python Op Scripts
- Example: Customize Output of the show interfaces terse Command Using an Op Script
- Example: Display DNS Hostname Information Using an Op Script
- Example: Find LSPs to Multiple Destinations Using an Op Script
- Example: Restart an FPC Using an Op Script
- Example: Export Files Using an Op Script
- Example: Import Files Using an Op Script
- Example: Search Files Using an Op Script
- play_arrow Provision Services Using Service Template Automation
- play_arrow Troubleshoot Op Scripts
-
- play_arrow Event Policies and Event Scripts
- play_arrow Event Policy Overview
- play_arrow Event Policy Triggers
- Use Correlated Events to Trigger an Event Policy
- Trigger an Event Policy Based on Event Count
- Example: Trigger an Event Policy Based on Event Count
- Use Regular Expressions to Refine the Set of Events That Trigger a Policy
- Example: Controlling Event Policy Using a Regular Expression
- Generate Internal Events to Trigger Event Policies
- Use Nonstandard System Log Messages to Trigger Event Policies
- Junos Logger Utility
- play_arrow Event Policy Actions
- Configure an Event Policy to Execute Operational Mode Commands
- Configure an Event Policy to Change the Configuration
- Example: Changing the Configuration Using an Event Policy
- Example: Changing the Interface Configuration in Response to an Event
- Execute Event Scripts in an Event Policy
- Change the Configuration Using an Event Script
- Configuring an Event Policy to Pass Arguments to an Event Script
- Configure Event Policies to Ignore an Event
- Example: Ignore Events Based on Receipt of Other Events
- Overview of Using Event Policies to Raise SNMP Traps
- Example: Raise an SNMP Trap in Response to an Event
- Understanding the Event System Log Priority in an Event Policy
- Example: Configuring the Event System Log Priority in an Event Policy
- Example: Limit Event Script Output Based on a Specific Event Type
- play_arrow Configure Event Policy File Archiving
- play_arrow Configure Event Policy Privileges
- play_arrow Event Scripts Overview
- play_arrow Create and Execute Event Scripts
- play_arrow Troubleshoot Event Policies and Event Scripts
-
- play_arrow SNMP Scripts
- play_arrow SNMP Scripts Overview
- play_arrow Create and Execute SNMP Scripts
- play_arrow SNMP Script Example
- play_arrow Troubleshoot SNMP Scripts
-
- play_arrow Configuration Statements and Operational Commands
XSLT Parameters Overview
Parameters can be passed to either named or unnamed templates. Inside the template, parameters must be declared and can then be referenced by prefixing their name with the dollar sign ($).
Declaring Parameters
The scope of a parameter can be global or local. A parameter whose value is set by Junos OS at script initialization must be defined as a global parameter. Global parameter declarations are placed just after the style sheet declarations. A script can assign a default value to the global parameter, which is used in the event that Junos OS does not give a value to the parameter.
<?xml version="1.0" standalone="yes"?> <xsl stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:junos="http://xml.juniper.net/junos/*/junos" xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm" xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0" xmlns:ext="http://xmlsoft.org/XSLT/namespace" version="1.0"> <!-- global parameter --> <xsl:param name="interface1"/>
Local parameters must be declared at the beginning of a block
and their scope is limited to the block in which they are declared.
Inside a template, you declare parameters using the <xsl:param>
tag and name
attribute. Optionally, declare
default values for each parameter by including the select
attribute, which can contain XPath expressions. If a template is invoked without the parameter, the
default expression is evaluated, and the results are assigned to the
parameter. If you do not define a default value in the template, the
parameter defaults to an empty string.
The following named template print-host-name
declares the parameter message
and defines
a default value:
<xsl:template name="print-host-name"> <xsl:param name="message" select="concat('host-name: ', system/host-name)"/> <xsl:value-of select="$message"/> </xsl:template>
The template accesses the value of the message
parameter by prefixing the parameter name with the dollar sign ($).
Passing Parameters
When you invoke a template, you pass arguments into the template
using the <xsl:with-param>
element and name
attribute. The value of the <xsl:with-param>
name
attribute must match the name of
a parameter defined in the actual template; otherwise the parameter
is ignored. Optionally, for each parameter you pass to a template,
you can define a value using either the select
attribute or the contents of the <xsl:with-param>
element.
The parameter value that gets used in a template depends on
how the template is called. The following three examples, which call
the print-host-name
template, illustrate
the possible calling environments.
If you call a template but do not include the <xsl:with-param>
element for a specific parameter, the default expression defined
in the template is evaluated, and the results are assigned to the
parameter. If there is no default value for that parameter in the
template, the parameter defaults to an empty string. The following
example calls the named template print-host-name
but does not include any parameters in the call. In this case, the
named template will use the default value for the message
parameter that was defined in the print-host-name
template, or an empty string if no default exists.
<xsl:template match="configuration"> <xsl:call-template name="print-host-name"/> </xsl:template>
If you call a template and include a parameter, but do not define
a value for the parameter in the calling environment, the script passes
in the current value of the parameter if it was previously initialized,
or it generates an error if the parameter was never declared. The
following example calls the named template print-host-name
and passes in the message
parameter,
but does not include a value. If message
is declared and initialized in the script, and the scope is visible
to the block, the current value of message
is used. If message
is declared in the
script but not initialized, the value of message
will be an empty string. If message
has
not been declared, the script produces an error.
<xsl:template match="configuration"> <xsl:call-template name="print-host-name"> <xsl:with-param name="message"/> </xsl:call-template> </xsl:template>
If you call a template, include the parameter, and define a
value for the parameter, the template uses the provided value. The
following example calls the named template print-host-name
with the message
parameter and a defined
value, so the template uses the new value.
<xsl:template match="configuration"> <xsl:call-template name="print-host-name"> <xsl:with-param name="message" select=concat"('Host-name passed in: ', system/host-name)"/> </xsl:call-template> </xsl:template>
Example: Parameters and Match Templates
The following template matches on /
, the root of the XML document. It then generates an element named <outside>
, which is added to the output document,
and instructs the Junos OS management process (mgd) to recursively apply templates to the configuration/system
subtree. The parameter host
is used in
the processing of any matching nodes.The value of the host
parameter is the value of the host-name
statement at the [edit system
] level of the configuration
hierarchy.
<xsl:template match="/"> <outside> <xsl:apply-templates select="configuration/system"> <xsl:with-param name="host" select="configuration/system/host-name"/> </xsl:apply-templates> </outside> </xsl:template>
The following template matches the <system>
element, which is the top of the subtree selected in the previous
example. The host
parameter is declared
with no default value. An <inside>
element
is generated, which contains the value of the host
parameter that was defined in the <xsl:with-param>
tag in the previous example.
<xsl:template match="system"> <xsl:param name="host"/> <inside> <xsl:value-of select="$host"/> </inside> </xsl:template>
Example: Parameters and Named Templates
The following named template report-changed
declares two parameters: dot
, which defaults
to the current node, and changed
, which
defaults to the changed
attribute of the
node dot
.
<xsl:template name="report-changed"> <xsl:param name="dot" select="."/> <xsl:param name="changed" select="$dot/@changed"/> <!-- ... --> </xsl:template>
The next stanza calls the report-changed
template and defines a source for the changed
attribute different from the default source defined in the report-changed
template. When the report-changed
template is invoked, it will use the newly defined source for the changed
attribute in place of the default source.
<xsl:template match="system"> <xsl:call-template name="report-changed"> <xsl:with-param name="changed" select="../@changed"/> </xsl:call-template> </xsl:template>
Likewise, the template call can include the dot
parameter and define a source other than the default current node,
as shown here:
<xsl:template match="system"> <xsl:call-template name="report-changed"> <xsl:with-param name="dot" select="../../> </xsl:call-template> </xsl:template>
Additional Examples
For complete examples that use the <xsl:param>
element in
automation scripts, see the following: