Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

first-of() Function (SLAX and XSLT)

Namespaces

SLAX Syntax

XSLT Syntax

Description

Return the first nonempty (non-null) item in a list. If all objects in the list are empty, the default expression is returned. This function provides the same functionality as an if / else-if / else construct but in a much more concise format.

The prefix associated with the namespace URI should be defined in the prefix-to-namespace mapping in the style sheet.

Parameters

expression

Default value returned if all objects in the list are empty.

object

List of objects.

Return Value

result

First nonempty (non-null) item in the object list. If all objects in the list are empty, the default expression is returned.

Usage Examples

In the following example, if the value of $a is empty, $b is checked. If the value of $b is empty, $c is checked. If the value of $c is empty, $d is checked. If the value of $d is empty, the string "none" is returned.

In the following example, for each physical interface, the script checks for a description of each logical interface. If a logical interface description does not exist, the function returns the description of the (parent) physical interface. If the parent physical interface description does not exist, the function returns a message that no description was found.

The equivalent XSLT code is:

The code for the description variable declaration in the previous examples would be equivalent to the following more verbose if / else-if / else construct:

See also Example: Display DNS Hostname Information Using an Op Script.

Release Information

Function introduced in Junos OS Release 7.6.

Support for the slax namespace http://xml.libslax.org/slax added in Junos OS Release 12.2.