[j-nsp] initialize multiple mutable variables in SLAX with the same value
Martin T
m4rtntns at gmail.com
Fri Mar 9 04:23:44 EST 2018
On Thu, Mar 8, 2018 at 7:47 AM, Phil Shafer <phil at juniper.net> wrote:
> Martin T writes:
>>I would like to initialize multiple mutable variables with the same
>>value. I could initialize variables one by one like this:
>
> There's no sort of run-time variable naming like this in SLAX.
> Variable names are just plain tokens (qnames).
>
> If your data is an array, consider using a single variable
> that contains a set of values, like:
>
> var $x := {
> <item> "one";
> <item> "two";
> <item> "three";
> }
>
> so $x[1] is "one" (position() is 1-origin). This allows
> building data like:
>
> var $x := {
> for-each (some/other/thing) {
> <item> .;
> }
> }
>
> But this makes updating a single array member difficult.
>
> The root of this is that XSLT (and SLAX) use a very different
> programming model than traditional languages, one that lends itself
> to recursion and immutable variables. In general, you are better
> off following that model.
>
> That said, sometimes it's easier to thing of a problem in traditional
> patterns. For more background on mutable variables into SLAX:
>
> http://juniper.github.io/libslax/slax-manual.html#mutable-variables-2
>
> Thanks,
> Phil
Thank you for confirming this! In addition, the inner workings of
libslax mutable variables was an interesting read.
Martin
More information about the juniper-nsp
mailing list