Data templates and transformations > Data transformations > Using local variables in transformations > Example – using a variable to access lookup data

Example – using a variable to access lookup data
In this example the data template contains a lookup table that is not included in the source data. The XPath function tdt:template is used to access the lookup table (see tdt:template() for more information about this function).
Data source
<data>
<message>
<issue id="123" status="i"/>
<issue id="789" status="f"/>
<issue id="007" status="c"/>
</message>
</data>
Expected resut
<data>
<issues>
<issue id="123">In Progress</issue>
<issue id="789">Resolved</issue>
<issue id="007">Closed</issue>
</issues>
</data>
Data template
<data>
<stmap>
<status value="i">In Progress</status>
<status value="f">Resolved</status>
<status value="c">Closed</status>
</stmap>
<issues>
<issue id="?"/>
</issues>
</data>
To make this work you must create a rule for the node /data/issues/issue in the template, and use a repeater in this rule to reference /data/message/issue in the source data.
Now that you have referenced the <issue> element in the source data you have access to its attributes, and can create a transformation variable $status for the @status attribute.
The value of the <issue> element in the output should be retrieved from the lookup table, and the $status variable determines which node to retrieve the value from. This is the value of the <status> element that has a @value attribute that equals the value of $status. To achieve this you can use the following XPath:
tdt:template()/data/stmap/status[@value=$status]
The following example summarizes what is described above.
/data/message/issue
$status
@status
text()
tdt:template()/data/stmap/status[@value=$status]
If you had not used a transformation variable, the result would not be the expected: tdt:template()/data/stmap/status[@value=@status]
This XPath selects <status> elements having equal @value and @status values.
OpenText StreamServe 5.6.2 Updated: 2018-01-26