Supported Platforms
Related Documentation
- ACX, EX, M, MX, PTX, SRX, T Series
- Summary of Extension Functions in the jcs and slax Namespaces
- Junos Script Automation: Named Templates in the jcs Namespace Overview
- Junos Script Automation: Global Parameters and Variables in the junos.xsl File
- SLAX Variables Overview
- ACX, EX, M, MX, SRX, T Series
- XSLT Variables Overview
Junos Script Automation: Understanding Extension Functions in the jcs and slax Namespaces
The Junos OS and SLAX extension functions are used in commit, op, and event scripts to accomplish scripting tasks more easily. Extension functions allow you to perform operations that are difficult or impossible to perform in XPath. The libraries provide logic, data manipulation, input and output, and utility functions.
Junos OS extension functions have functionality that is specific to devices running Junos OS. Junos OS extension functions are defined in the namespace with the associated Uniform Resource Identifier (URI) http://xml.juniper.net/junos/commit-scripts/1.0 . To use Junos OS extension functions in scripts, you must include the namespace URI in your style sheet declaration. Generally, the jcs prefix is mapped to the URI, and you then use the extension functions by prepending the jcs prefix to the function name. This avoids name conflicts with standard XSLT functions. During processing, the jcs prefix is expanded into the URI reference.
The following SLAX namespace statement maps the jcs prefix to the namespace URI that defines Junos OS extension functions used in commit, op, and event scripts:
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
SLAX extension functions are defined in the namespace with the associated URI http://xml.libslax.org/slax . To use SLAX extension functions in scripts, you must include the namespace URI in your style sheet declaration. Generally, the slax prefix is mapped to the URI, and you then use the extension functions by prepending the slax prefix to the function name. During processing, the slax prefix is expanded into its associated URI reference.
The following SLAX namespace statement maps the slax prefix to the namespace URI that defines SLAX extension functions:
ns slax = "http://xml.libslax.org/slax";
The slax namespace is supported starting with Junos OS Release 12.2. Scripts using Junos OS-independent extension functions that existed in earlier releases in the jcs namespace can use either the jcs or the slax namespace starting with Junos OS Release 12.2. However, to use any of these functions in earlier Junos OS releases, scripts must use the jcs namespace URI. For a list of available functions and associated namespaces, see Summary of Extension Functions in the jcs and slax Namespaces.
To call an extension function in a script, include any required variable declarations, call the function using jcs:function-name() or slax:function-name() as appropriate, and pass along any required or optional arguments. Arguments must be passed into the function in the precise order specified by the function definition. This is different from a template, where the parameters are assigned by name and can appear in any order. The return value of an extension function must always either be assigned to a variable or designated as output.
The following example maps the jcs prefix to the namespace identified by the URI http://xml.juniper.net/junos/commit-scripts/1.0 . The script then calls the jcs:invoke() function with one argument.
XSLT Syntax
<?xml version=”1.0”?>
<xsl:stylesheet version=”1.0”
xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0">
...
<xsl:variable name="result" select="jcs:invoke($command)"/> ...
</xsl: stylesheet>
SLAX Syntax
version 1.0;
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0"; ...
var $result = jcs:invoke($command); ...
The following example maps the slax prefix to the namespace identified by the URI http://xml.libslax.org/slax . The script then calls the slax:get-input() function with one string argument. The version statement specifies version 1.1 of the SLAX language, which is supported in Junos OS Release 12.2 and later releases.
SLAX Syntax
version 1.1;
ns slax = "http://xml.libslax.org/slax"; ...
var $input = slax:get-input($prompt); ...
Related Documentation
- ACX, EX, M, MX, PTX, SRX, T Series
- Summary of Extension Functions in the jcs and slax Namespaces
- Junos Script Automation: Named Templates in the jcs Namespace Overview
- Junos Script Automation: Global Parameters and Variables in the junos.xsl File
- SLAX Variables Overview
- ACX, EX, M, MX, SRX, T Series
- XSLT Variables Overview
Published: 2013-03-05
Supported Platforms
Related Documentation
- ACX, EX, M, MX, PTX, SRX, T Series
- Summary of Extension Functions in the jcs and slax Namespaces
- Junos Script Automation: Named Templates in the jcs Namespace Overview
- Junos Script Automation: Global Parameters and Variables in the junos.xsl File
- SLAX Variables Overview
- ACX, EX, M, MX, SRX, T Series
- XSLT Variables Overview