Variables

Previous Next

Setting a variable

In USoft Blend, you can use the following assignment directives to create a named variable and set it to a value.

As you can see, each variable you create is explicitly typed. Each of the available assignment directives maps to one of the 4 XSLT data types.

In practice, most Blend scripts are simple utilities that do not require strong typing. You should regard pc:assign-string as the default for Blend variables. Occasionally it is important to be able to accept a node set value as a node set and not as a string value. Also, occasionally, you want to calculate with number values (as in $portnumber + 1), in which case you must cast to the number type and not to the string type.

Each assignment directive has a ...-default counterpart. Use this counterpart if you want to set the value only if the variable is not already known (with an existing value). In other words, use the ...-default counterparts if you want to prevent overwrites.

set variable, overwrite if exists

set variable only if not exists (ie., prevent overwrite)

pc:assign-boolean

pc:assign-boolean-default

pc:assign-nodeset

pc:assign-nodeset-default

pc:assign-number

pc:assign-number-default

pc:assign-string

pc:assign-string-default

 

Other directives and attributes relating to variable assignment include:

assign:variable

Equivalent to assignment directives, but using an XML attribute instead of an XML element.

pc:define-boolean-flags

Adds items to the list of pairs of strings interpreted as boolean true() and boolean false() by "flag-based" string-to-boolean conversion.

pc:GetVariables

Returns the list of Blend variable declarations currently referenced.

pc:LoadVariablesDefault

Retrieves from a file a list of Blend variable declarations, NOT overwriting any existing variables with the same names.

pc:LoadVariablesOverwrite

Retrieves from a file a list of Blend variable declarations, overwriting any existing variables with the same names.

pc:SaveVariables

Save to a file the list of Blend variable declarations currently referenced.

 

Getting a variable

You can get the value of an instantiated variable by using the standard XSLT variable reference syntax:

$variable

Example 1

This example outputs a string value:

<pc:value-of select="$myvariable"/>

Example 2

This example outputs a node set value:

<pc:copy-of select="$myvariable"/>