pc:assign-var

Previous Next

Evaluates an expression and stores the resulting value in (= assigns the resulting value to) a named variable. That variable is global: from any later script section you can refer to its value by writing $variable.

If a variable by the same name is already instantiated, its value is silently overwritten. This is the difference with pc:assign-var-default.

You have the option to assign multiple variables in a single pc:assign-var directive.

Syntax

<pc:assign-var
     variable = "expr"
  [  variable = "expr" ... ] />

For each variable, variable identifies the variable by name and expr is the value you provide for the variable. Expr may be submitted either as a literal or as an XPath expression presented as an attribute value template, ie., surrounded by curly braces ( {  } ).

 

Example

<pc:assign-var
     username="ADMIN"
     workingdir="{directories:Get()}"
     servername="{path:GetFileName(directories:Get())}" />

XPath datatypes

If the variable's value is supplied by an XPath expression, as in the last 2 variables of the Example, the result value is typed as being of 1 of the 4 XPath datatypes (nodeset, string, number, boolean). pc:assign-var does not interfere with this. If you require explicit conversion to a specific (different) datatype, use one of these directives instead:

pc:assign-nodeset

pc:assign-string

pc:assign-number

pc:assign-boolean

 

See also

pc:assign-var-default

Variables

assign:variable