Skip to content
Tech News
← Back to articles

The SLAX Scripting Language: An Alternate Syntax for XSLT

read original more articles
Why This Matters

The SLAX scripting language introduces an alternative syntax for XSLT, offering features like a C-style ternary operator and mechanisms to simulate mutable variables, which address some of the limitations of traditional XSLT. This development is significant for the tech industry as it enhances scripting flexibility and performance, especially in environments like JUNOS where XML-based RPCs are common. However, considerations around portability and environment compatibility remain important for developers.

Key Takeaways

This section includes discussion of SLAX language issues.

Section Contents:

For example, the expression "chapter[starts-with(section, 'A')]" will inspect all <chapter> elements, convert their <section> elements to strings, and select those whose string value starts with 'A'. This may be an expensive operation.

Similarly, if a predicate uses a function that needs a string, the argument is converted to a string value by concatenating all the text values of that node and all that node's child elements.

For example, the expression "chapter[section]" selects all chapters that have a section element as a child.

XPath expressions use a style of type promotion that coerces values into the particular type needed for the expression. For example, if a predicate refers to a node, then that predicate is true if the node exists. The value of the node is not considered, just it's existence.

The caveat is that this uses an extension function slax:value() which may not be available in all XSLT environments. Coders must consider whether should a restriction deems this operator unusable. Portability considerations are identical to mutable variables (mvars).

As the last touch to SLAX-1.1, I've added the ternary operator from C, allowing expressions like:

XSLT has immutable variables. This was done to support various optimizations and advanced streaming functionality. But it remains one of the most painful parts of XSLT. We use SLAX in JUNOS and provide the ability to perform XML-based RPCs to local and remote JUNOS boxes. One RPC allows the script to store and retrieve values in an SNMP MIB (the jnxUtility MIB). We have users using this to "fake" mutable variables, so for our environment, any theoretical arguments against the value of mutable variables are lost. They are happening, and the question becomes whether we want to force script writers into mental anguish to allow them.

Yes, exactly. That was an apologetical defense of the following code, which implements mutable variables. Dio, abbi pieta della mia anima.

... continue reading