Skip to content

NewIn1 1

Phil Shafer edited this page Jul 9, 2013 · 8 revisions

New Features in SLAX-1.1

New Statements for Existing XSLT Elements

SLAX-1.1 includes complete support for all XSLT elements.

apply-imports

The apply-imports statement applies any templates imported from other files.

Read more in the docs.

attribute

The attribute statement creates an attribute, giving the name and value for the attribute. This is used when the attribute name is not static.

<data> {
    attribute $type _ $number {
        expr value;
    }
}

Read more in the docs.

attribute-set

The attribute-set statement defines a set of attributes.

Read more in the docs.

copy-node

The copy-node statement copies a node, while allowing additional content to be supplied.

copy-node . {
    <new> "content";
}

Read more in the docs.

decimal-format

The decimal-format statement defines details about the formatting of numbers.

Read more in the docs.

element

The element statement creates an element, giving a name and contents for that element. This is used when the element name is not static.

element $type _ $number {
    expr "content";
}

Read more in the docs.

fallback

The fallback statement is used when an extension element or function is not available.

Read more in the docs.

key

The key statement defines a key.

Read more in the docs.

message

The message statement generates an output message.

message "testing " _ this;

Read more in the docs.

number

The number statement emits a number.

Read more in the docs.

output-method

The output-method statement declares the output method to use when generating the results of the transformation.

Read more in the docs.

preserve-space

The preserve-space statement defines elements for which internal whitespace is to be preserved.

Read more in the docs.

sort

The sort statement defines the order in which the for-each or apply-templates statements visit a set of nodes.

Read more in the docs.

strip-space

The strip-space statement defines elements for which internal whitespace is to be removed.

Read more in the docs.

terminate

The terminate statement terminates a script, giving a message.

Read more in the docs.

uexpr

The uexpr statement emits a values which is not escaped.

Read more in the docs.

use-attribute-sets

The use-attribute-sets statement uses the set of attributes defined by an attribute-set statement.

Read more in the docs.

Mutable Variables

SLAX-1.1 introduces mutable variables, whose values can be changed. Mutable variables are not part of XSLT and their use can make your script unportable to other XSLT engines. See Mutable Variables for associated issues.

append

The append statement appends a value to a mutable variable.

append $mvar += <new> "content";

Read more in the docs.

mvar

The mvar statement declares a mutable variable.

mvar $mvar;

Read more in the docs.

set

The set statement sets the value of a mutable variable.

set $mvar = <my> "content";

Read more in the docs.

while

The while statement is a control statement that loops until the text expression is false. Note that this is only possible if the test expression contains a mutable variable.

while (count($mvar) < 10) {
    /* do more work */
}

Read more in the docs.

New SLAX Statements

SLAX-1.1 defines a new set of statements, providing additional functionality for SLAX scripts.

for

The for statement is a control statement that iterates thru a set of values, assigning each to a variable before evaluating a block of statements.

for $i ($min ... $max) {
    <elt> $i;
}

Read more in the docs.

function

The function statement defines an extension function, usable in XPath expressions.

function my:lesser ($a, $b) {
    if ($a < $b) {
        result $a;
    } else {
        result $b;
    }
}

Functions use the EXSLT function package.

Read more in the docs.

result

The result statement defines the result value for a function.

Read more in the docs.

trace

The trace statement allows trace data to be written to the trace file.

trace "my debug value is " _ $debug;
trace {
    if ($debug/level > 4) {
        <debug> {
            copy-of $data;
        }
    }
}

Read more in the docs.

New SLAX Operators

Sequences ("...")

The sequence operator ("...") creates a sequence of elements between two integer values. Two values are used, with the "..." operator between them. The values are both included in the range. If the first value is less than the second one, the values will be in increasing order; otherwise the order is decreasing.

for $tens (0 ... 9) {
    message "... " _ tens _ "0 ...";
    for $ones (0 ... 9) {
        call test($value = $tens * 10 + $ones);
    }
}

Read more in the docs.

Node-set Assignment (":=")

The node-set assignment operator (":=") assigns a node-set while avoiding the evils of RTFs. This allows the assigned value to be used directly without the need for the node-set() function.

var $data := {
    <one> 1;
    <two> 2;
    <three> 3;
    <four> 4;
}

var $name = $data/*[. == $count];

Read more in the docs.

Ternary Operator ("?:")

The ternary operator ("?:") makes a simple inline if/else test, in the pattern of C/Perl. Two formats are supported. The first format gives a condition, the value if the condition is true, and the value if the condition is false. The second format uses the first value if the condition is true and the second if it is false.

var $class = (count(items) < 10) ? "small" : "large"; var $title = data/title ?: "unknown";

Read more in the docs.

Pound-Bang ("#!")

SLAX supports the use of "#!/path/to/slaxproc" as the first line of a SLAX script. This allows scripts to be directly executable from the unix shell.

Read more in the docs.