-
Notifications
You must be signed in to change notification settings - Fork 20
Intro
SLAX is an alternative syntax for XSLT which is tailored for readability and familiarity, following the style of C and Perl. Programming constructs and XPath expressions are moved from the XML elements and attributes used in XSLT to first class language constructs. The overabundance of angle brackets and quotes is replaced by the more familiart parentheses and curly braces.
SLAX allows you to:
- Use if/then/else instead of
<xsl:choose>
and<xsl:if>
elements - Use curly braces to show containment instead of closing tags
- Write text strings using quotes instead of the
<xsl:text>
element - Put test expressions in parentheses
- Use "==" to test equality (to avoid building dangerous habits)
- Perform concatenation using the underscore operator
- Invoke named templates with a syntax resembling a function call
- Define named template with a syntax resembling a function definition
- Simplify namespace declarations
- Reduce the clutter in scripts, allowing the important parts to be more obvious to the reader
- Write more readable scripts
The benefits of SLAX are particularly strong for new developers, since it puts familiar constructs in familiar syntax, allowing them to concentrate in the new topics introduced by XSLT.
Here is a simple example script:
version 1.1; /* All scripts start with "version" */
param $name = "Poe"; /* Script parameters with default values */
var $favorites := { /* ":=" avoids RTFs */
<name hidden="yes"> "Spillane";
<name> "Doyle"; /* Creates elements and attributes */
<name> "Poe";
}
match / { /* A match template */
<out> {
/* Parameters are passed by name to templates */
call test($elt = "author", $name);
}
}
template test ($name, $elt = "default") {
for $this ($favorites/name) {
if ($name == $this && not($this/@hidden)) {
element $elt {
copy-of .//author[name/last == $this];
}
} else if ($name == $this) {
message "Hidden: " _ $name;
}
}
}
The XSLT version of this script is also available and the "slaxproc" program can be used to easily convert between the two formats.
Also see the complete documentation for the SLAX language.
libslax includes the "slaxproc" utility, which can be used to run scripts and to convert between XSLT and SLAX. "slaxproc" also includes a gdb-like debugger and a simple profiler.