Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

SLAX Statements Overview


This section lists some commonly used SLAX statements, with brief examples and XSLT equivalents.

for-each Statement

The SLAX for-each statement functions like the <xsl:for-each> element. The statement consists of the for-each keyword, a parentheses-delimited expression, and a curly braces-delimited block. The for-each statement tells the processor to gather together a set of nodes and process them one by one. The nodes are selected by the specified XPath expression. Each of the nodes is then processed according to the instructions held in the for-each code block.

Code inside the for-each instruction is evaluated recursively for each node that matches the XPath expression. That is, the current context is moved to each node selected by the for-each clause, and processing is relative to that current context.

In the following example, the inventory variable stores the inventory hierarchy. The for-each statement recursively processes each chassis-sub-module node that is a child of chassis-module that is a child of the chassis node. For each chassis-sub-module element that contains a part-number with a value equal to the specified part number, a message element is created that includes the name of the chassis module and the name and description of the chassis sub module.

The XSLT equivalent is:

if, else if, and else Statements

SLAX supports if, else if, and else statements. The if statement is a conditional construct that causes instructions to be processed if the specified XPath expression evaluates to true. The if construct may have one or more associated else if clauses, each of which tests an XPath expression. If the expression in the if statement evaluates to false, the processor checks each else if expression. If a statement evaluates to true, the script executes the instructions in the associated block and ignores all subsequent else if and else statements. The optional else clause is the default code that is executed in the event that all associated if and else-if expressions evaluate to false. If all of the if and else if statements evaluate to false, and the else statement is not present, no action is taken.

The expressions that appear in parentheses are extended XPath expressions, which support the double equal sign (==) in place of XPath’s single equal sign (=).

During script processing, an if statement that does not have an associated else if or else statement is transformed into an <xsl:if> element. If either the else if or else clauses are present, the if statement and associated else if and else blocks are transformed into an <xsl:choose> element.

The XSLT equivalent is:

match Statement

You specify basic match templates using the match statement, followed by an expression specifying when the template should be allowed and a block of statements enclosed in a set of braces.

The XSLT equivalent is:

For more information about constructing match templates, see SLAX Templates Overview.

ns Statement

You specify namespace definitions using the SLAX ns statement. This consists of the ns keyword, a prefix string, an equal sign, and a namespace Uniform Resource Identifier (URI). To define the default namespace, use only the ns keyword and a namespace URI.

The ns statement can appear after the version statement at the beginning of the style sheet or at the beginning of any block.

When it appears at the beginning of the style sheet, the ns statement can include either the exclude or extension keyword. The keyword instructs the parser to add the namespace prefix to the exclude-result-prefixes or extension-element-prefixes attribute.

The XSLT equivalent is:

version Statement

All SLAX style sheets must begin with a version statement, which specifies the version number for the SLAX language. Supported versions include 1.0 and 1.1. SLAX version 1.0 uses XML version 1.0 and XSLT version 1.1.

The XSLT equivalent is:

Related Documentation