Skip to main content
Windward

Set Tag Reference

Overview

 


Set Tag: <wr:set ... > 


 

 

Use the Set Tag to set the value of a variable. The name of this variable can subsequently be used in other tags as a relative data reference, using ${name}.

The purpose of this tag is to create a value that can be referenced by other tags. While it can be used in other ways under some data providers, results are not guaranteed for any other use.

 

This is different from the Query Tag in that it sets a string to the value, not a dataset.

 

Attributes

  • var – required. Set the name to use for this variable.
  • value – optional. Set the value to use for this variable.
  • evaluate – optional. Evaluates an expression and returns the result.

 

Using Set Variables Across Data Sources

A Set Tag, like every other tag, is only evaluated by the datasource it is assigned to. However, the variable created by a Set Tag is carried over to the remaining datasources. This variable can then be used and changed by other datasources.

 

For example:

 

1.     Pretend we have a datasource called DS1

2.     The template contains a Set Tag  - <wr:set var="count" select="3" datasource="DS1"/>

3.     We can use an Out Tag to display our value - <wr:out select="${count}"  datasource="DS1"/> - will print a "3" in the output

4.     Now, DS1 fully processed. There are no datasource='DS1' tags in the report we are generating at this point.

5.     Not let’s process a second datasource called DS2

6.     Create another Out Tag to display a value - <wr:out select="${count}"  datasource="DS2"/> - will print a "3" in the output

7.     Create another Set Tag - <wr:set var="count" select="${count} + 2" datasource="DS2"/> - note that we are using the DS2 datasource here.

8.     Now, use another Out Tag - <wr:out select="${count}"  datasource="DS2"/> - will print a "5" in the output

 

There are several things to keep in mind here:

 

  • The Set Tag is processed only by the datasource it is assigned to. What is retained across data sources is the variable and value held in the Engine's internal list of variables.
  • If you assign a variable with this same name to a datasource before it processes, then this new value will override the value set in the previous processing.
  • All variable names are kept in the same list. If you have a ForEach, Query, or Out Tag with var="count", that will override the value saved.

 

Examples

 

Let’s use a search and replace example.

In the following example, any use of ${name} in a tag will be converted to ‘Dave’. This is a pure text search & replace:

  • We can use a Set Tag to give it a value of ‘Dave’ - <wr:set var="name" value="Dave"/>
  • You can also evaluate a statement with a Set Tag. This returns the results of an expression. In the example below, anywhere you use ${name} it is changed to 15.
    • <wr:set var=’name’ evaluate=’3 * 5’/>
  • Another use of a Set Tag is using true or false values. In the example below, anywhere you use ${name} it is changed to have a true value.
    • <wr:set var=’name’ evaluate=’3 < 5’/>

 

Note For Version 10 And Later


Using the attribute “value” <expression> cannot contain XPath functions anymore like in older Windward versions.

  • <wr:set var=”<name>” value=”<expression>”/>

In order to get XPath functionality use the attribute “select=” instead:

  • <wr:set var=”<name>” select=”<expression>”/>

In this context <expression> must not necessarily have data access.

You can use XPath functions and operators to process wr:set variables which have been previously defined. These are normally of type string. In order to use mathematical operators, you must convert the string using “number()”.

 

Here is an example:

The following expression will be used to raise a number by 1 within a loop used in earlier versions:

  • <wr:set var="ALT_NUMBER" value = " ${ALT_NUMBER}+1"/>

Using Windward version 10 or later, it must be replaced by:

  • <wr:set var="ALT_NUMBER" select = "number(${ALT_NUMBER})+1"/>
  • Was this article helpful?