ends-with() Function (SLAX)
Namespaces
http://xml.libslax.org/slax
SLAX Syntax
var $boolean = slax:ends-with(string, substring);
Description
Return true if the string ends with the specified substring. This function is useful for testing for file extensions and other trailing strings.
Parameters
string |
String to test if it ends with the given substring. |
substring |
Substring to check for at the end of the test string. |
Return Value
boolean |
Boolean value, which is |
Usage Examples
The following example presents a simple script that reviews each op script filename in the
configuration. The ends-with function tests if a script is a Python script
(ends with .py) or a SLAX script (ends with .slax).
version 1.3;
ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
ns slax = "http://xml.libslax.org/slax";
import "../import/junos.xsl";
match / {
var $config-rpc = <get-configuration>;
var $config = jcs:invoke( $config-rpc );
for-each ($config/system/scripts/op/file) {
if (slax:ends-with(name, ".py")) {
expr jcs:output("Python script");
/* perform operations for Python scripts */
} else if (slax:ends-with(name, ".slax")) {
expr jcs:output("SLAX script");
/* perform operations for SLAX scripts */
}
}
}
Release Information
Function introduced in SLAX version 1.3.