SLAX Elements as Function Arguments
Starting with SLAX version 1.2, you can use SLAX elements directly as arguments for both functions and templates. Function arguments can either be a single element or a block of SLAX code, placed inside braces as shown in the following example:
var $a = my:function(<elt>,<max> 15);
var $b = my:test ({
<min> 5;
<max> 15;
if ($step) {
<step> $step;
}
});var $c = my:write(<content> {
<document> "total.txt";
<size> $file/size;
if (node[@type == "full"]) {
<full>;
}
});For templates, you still need to include the argument name, but the value can be inline. For example:
call my:valid($name = <name> $input, $object = {
<min> $min;
<max> $max;
});The Main Template
Starting with SLAX version 1.2, the main template is introduced in SLAX.
The main template enables you to process the input XML document and
provide the top-level element for the output hierarchy. The main
template is equivalent to using match / but slightly more
convenient.
You can use the main statement to
match the top of the input data hierarchy and create the top-level
tag of the output hierarchy. You can use the statement in two forms:
with or without the output tag. When you omit the output element, main is just followed by a block of statements within
a set of braces, as shown in the following example:
main {
<top> {
<answer> 42;
}
}
The main template can also be used
with a top-level output element following the main token, as shown in the following example:
main <top> {
<answer> 42;
}Both of the preceding examples are equivalent to the following XSLT version:
<xsl:template match="/">
<top>
<answer>42</answer>
</top>
</xsl:template>