assign:variable

Previous Next

Evaluates an XPath expression and stores it in (= assigns it to) a named variable. The 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 in use, the value it currently holds is silently overwritten.

The result of executing this attribute is equivalent to executing one of the following assingment directives, except that it is an XML attribute rather than an XML element:

pc:assign-boolean

pc:assign-nodeset

pc:assign-number

pc:assign-string

TIP: You can provide a default value for a parameter in case it is not passed when your script is called. Use one of these directives:

pc:assign-boolean-default

pc:assign-nodeset-default

pc:assign-number-default

pc:assign-string-default

 

Syntax

<element
   assign:variable = "expr" />

The required variable identifies the variable by name and the required 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

This example executes a script ( ... ) for each of the "computer" elements found.

In each interation, the "name" attribute of "computer" is assigned to a variable called "result". This variable value may be referred to as $result.

<pc:each
   select="env/computers/computer"
   assign:result="@name" 
 
   ...
 
/>

Note

In assignment directives, the assign: namespace prefix is NOT used:

<pc:assign-string
     workingdir="{directories:Get()}"
     servername="{path:GetFileName(directories:Get())}" >

 

See also

Variables