You are viewing the documentation for Blueriq 18. Documentation for other versions is available in our documentation directory.
TSL stands for “Text Substitution Language”. So its predominant function is to substitute TSL-anchor at run-time, by the current attribute value.
Additional formatting of these substituted texts is available, for dates and numbers. Furthermore, by using TSL statements combined with functions and expressions, it enables you to create conditional text blocks.
TSL can be used in all Blueriq Studio assets.
TSL anchor
TSL anchors are used to mark attributes or expressions to be interpreted as TSL.
So if you want to use an attribute value in a text block, you insert the attribute at the position you want the value to appear and enclose it with TSL-anchors.
If you want to interpret an expression in a text block, place the expression between the TSL anchors.
Syntax
[text] [[[expr]]] [text]
- expr is an attribute or expression that you want interpreted by the TSL
- [text] plain text
Note: You cannot ‘nest’ anchors. So [[[<expr1>[[[< expr2>]]]]]] will result in an error.
Example
Suppose you want to create a welcoming message after a user has logged on to your application. Then you could create the following TSL message:
Welcome [[[user.first_name]]] [[[user.last_name]]]
When user John Doe logged in, the message shown in your application is: “Welcome John Doe”
Comment
You can use TSL comment tags in order to add comment to your TSL.
Syntax
/* [text] */
- /* open comment tag
- */ close comment tag
Example
/* The statement below creates a list of all user names. This is a multi line comment. */ [[[FOREACH user]]]Name: [[[user.last_name]]], [[[user.first_name]]][[[/FOREACH]]]
IF statement
The IF statement enables you to selectively perform tasks within your TSL message, based on some criteria which evaluate to TRUE or FALSE.
Syntax
[[[IF expr]]] message [[[/IF]]]
- Expr: is an expression that evaluates to TRUE or FALSE
- Message: is a TSL message, so it can contain plain text and other TSL conditions
Example
Suppose you want to create a welcoming message after a user has logged in to your application. Then you could create the following TSL message:
Welcome [[[IF user.gender = 'male']]]Mr.[[[/IF]]] [[[IF user.gender = 'female']]]Mrs.[[[/IF]]] [[[user.first_name]]] [[[user.last_name]]]
When user John Doe logged on, the message shown in your application is: “Welcome Mr. John Doe”
When user Jane Doe logged on, the message shown in your application is: “Welcome Mrs. Jane Doe”
If the gender is unknown the message will look like this: “Welcome Jane Doe”
IF ELSE statement
The IF ELSE statement enables you to selectively perform tasks within your TSL message, based on some criteria, which evaluate to TRUE or FALSE.
When TRUE executes the task specified in the IF part of the statement, in all other cases executes the task specified in the ELSE part of the statement.
Syntax
[[[IF expr]]] message1 [[[ELSE]]] message2 [[[/IF]]]
- expr: is an expression that evaluates to TRUE or FALSE
- message1 and message2: are TSL messages, so they can contain plain text and other TSL conditions
Example
Suppose you want to create a welcoming message after a user has logged in to your application. Then you could create the following TSL message:
Welcome [[[IF user.gender = 'male']]]Mr.[[[ELSE]]] Mrs.[[[/IF]]] [[[user.first_name]]] [[[user.last_name]]]
When user John Doe logged on, the message shown in your application is: “Welcome Mr. John Doe”
If the gender is unknown the message will look like this: “Welcome Jane Doe”
IF ELSEIF statement
The IF ELSEIF statement enables you to selectively perform tasks within your TSL message, based on some criteria, which evaluate to TRUE or FALSE.
When TRUE executes the task specified in the IF part of the statement, the task specified in the ELSEIF part of the statement is only executed when the specified criteria are met.
Syntax
[[[IF expr1]]] message1 [[[ELSEIF expr2]]] message2 [[[/IF]]]
- expr1 and expr2: are expressions which evaluate to TRUE or FALSE
- message1 and message2: are TSL messages, so they can contain plain text and other TSL conditions.
Example
Suppose you want to create a welcoming message after a user has logged in to your application. Then you could create the following TSL message:
[[[IF time.hour >= 0 AND time.hour < 6]]]Good night [[[ELSEIF time.hour >= 6 AND time.hour < 12]]]Good morning [[[ELSEIF time.hour >= 12 AND time.hour < 18]]]Good afternoon [[[ELSEIF time.hour >= 18 AND time.hour ⇐ 23]]]Good evening[[[/IF]]] [[[user.first_name]]] [[[user.last_name]]]
When user John Doe logged on at 8 o’clock am, the message shown in your application is: “Good morning John Doe”
When user John Doe logged on at 7 o’clock pm, the message shown in your application is: “Good evening John Doe”
FOREACH statement
Use this statement to repeat a text for each instance of an entity.
Syntax
[[[FOREACH entity]]] message [[[/FOREACH]]]
- Entity: is an entity name
- Message: is a TSL message, so it can contain plain text and other TSL conditions
Example
Suppose you want to create an overview of all registered users. Then you could create the following message:
[[[FOREACH user]]]Name: [[[user.last_name]]], [[[user.first_name]]][[[/FOREACH]]]
If you have three registered users: John Doe, Jane Doe and Mr X your user list would look like this: Name: Doe, John Name: Doe, Jane Name: X, Mr
FOREACH IN statement
Use this statement to repeat a text for a subset of instances of an entity.
Syntax
[[[FOREACH entity IN relation]]] message [[[/FOREACH]]]
- entity: is the child entity
- relation: is the relationship between the parent and the child entity
- message: is a TSL message, so it can contain plain text and other TSL conditions
Example
Suppose you created a parent and a child entity. The parent has a multivalue relation with the child via the attribute Parent.Has_Children.
If the following instances where created:
Parent instance | Parent.Name | Child instance | Child.Name | Child.Date_of_birth |
---|---|---|---|---|
Parent_1 | John | Child_1 | Kim | 26-September-1998 |
Child_2 | Rick | 13-May-2000 | ||
Child_3 | Bob | 3-August-2003 | ||
Parent_2 | Dave | Child_4 | Mary | 4-June-1982 |
To create an overview of the children per parent you could create the following TSL message:
[[[FOREACH Parent]]] [[[Parent.Name]]] has children: [[[FOREACH Child IN Parent.Has_children]]] Name: [[[Child.Name]]] Date of birth: [[[Child.Date_of_birth]]], [[[/FOREACH]]] [[[/FOREACH]]]
This results in:
John has children: Name: Kim Date of birth: 26-09-1998, Name: Rick Date of birth: 13-05-2000, Name: Bob Date of birth: 03-08-2003 Dave has children: Name: Mary Date of birth: 04-06-1982
You can combine the IN, WHERE and ORDER BY if you wish. Example:
Persons older than 40: [[[FOREACH Person IN TestEntity.rel WHERE Person.Age>10 ORDER BY Person.Age Asc]]] [[[Person.Name]]], [[[Person.Age]]]; [[[/FOREACH]]]
FOREACH WHERE statement
Use this statement to repeat a text for a subset of instances of an entity.
Syntax
[[[FOREACH entity WHERE condition]]] message [[[/FOREACH]]]
- entity: is the child entity
- condition: the condition that must hold for an instance
- message: is a TSL message, so it can contain plain text and other TSL conditions
Example
Suppose you have multiple persons. If the following instances where created:
Person instance | Person.Name | Age |
---|---|---|
Person_1 | John | 25 |
Person_2 | Peter | 31 |
Person_3 | Angela | 47 |
Person_4 | Dave | 82 |
To create an overview of all persons older than 40 you could create the following TSL message:
Persons older than 40: [[[FOREACH Person WHERE Person.Age>40]]] [[[Person.Name]]], [[[Person.Age]]]; [[[/FOREACH]]]
This results in:
Persons older than 40: Angela, 47; Dave, 82;
You can combine the IN, WHERE and ORDER BY if you wish. Example:
Persons older than 40: [[[FOREACH Person IN TestEntity.rel WHERE Person.Age>10 ORDER BY Person.Age Asc]]] [[[Person.Name]]], [[[Person.Age]]]; [[[/FOREACH]]]
FOREACH ORDER BY statement
When you use the FOREACH or FOREACH IN statement to repeat a text for multiple instances, you can add the ORDER BY statement to create an ordered list of texts. Add either DESC if you want to sort the list descending or ASC if you want to order the list ascending.
Syntax
FOREACH <entity> ORDER BY <attr> DESC|ASC FOREACH <entity> IN <relation> ORDER BY <attr> DESC|ASC
The ORDER BY statement has the following arguments:
- attr (Required) – the attribute by which the list of instances will be ordered
You can combine the IN, WHERE and ORDER BY if you wish. Example:
Persons older than 40: [[[FOREACH Person IN TestEntity.rel WHERE Person.Age>10 ORDER BY Person.Age Asc]]] [[[Person.Name]]], [[[Person.Age]]]; [[[/FOREACH]]]
Sequence
Use this operator to add a sequence-number to each instance in a set of instances.
Note: The sequence operator returns the sequence-number of the FOREACH loop that it is used in. It is not the sequence in which the instances where created.
Syntax
[[[#]]]
- # is the sequence operator
Example
Suppose you want to create an overview of all registered users. Then you could create the following message:
[[[FOREACH user]]][[[# user.last_name]]], [[[user.first_name]]][[[/FOREACH]]]
If you have three registered users: John Doe, Jane Doe and Mr X your user list would look like this: 1 Doe, John 2 Doe, Jane 3 X, Mr
Or you want to create a comma separated list that contains all users:
[[[FOREACH user]]] [[[user.first_name]]] [[[user.last_name]]] [[[IF # != (COUNT user.last_name)]]], [[[ELSE]]]. [[[/IF]]] [[[/FOREACH]]] /*end user loop*/
Than the result would look like this:
John Doe, Jane Doe, Mr X.
Formats
There are two different types of formatting available in TSL, number formats and date formats. Both formats are applied to attributes or expressions in the same way.
Syntax
[[[expression{format}]]]
- § expression: is a number or date
- § format: is the number or date formatting
Numbers
In TSL, you can use number formats to change the appearance of numbers, without changing the number behind the appearance. The number format you apply does not affect the actual value. In this context a number can be any of the following basetypes; number, integer, currency or percentage.
The number formats used in TSL are common Java 1.4 decimal formats. The most commonly used formatting symbols are listed below. For a complete documentation we refer to the online java documentation that is available at http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html.
Symbol | Name | Meaning |
---|---|---|
0 | Digit_zero | displays insignificant zeros if a number has fewer digits than there are zeros in the format |
# | Digit | displays only significant digits and does not display insignificant zeros |
, | Thousand separator | The integer portion of a number is often split into groups by a grouping separator. Western numbers generally separate numbers into thousands, or groups of 3 digits. However, other styles exist. |
. | Decimal separator | The separator between integer and fractional parts of a number |
- | Minus sign | Sign to specify a negative value |
; | Sub pattern separator | Separates formatting for positive and negative numbers |
% | Percentage sign | Multiply by 100 and show as percentage |
¤(ALT_0164) | Currency sign | Use localized currency symbol (for € sign simply use ALT_0128) |
‘ | Escape character | Use special characters as ordinary characters |
These symbols are used to create a format pattern. How this pattern is created is shown in the examples below.
Note: the following characters have a special meaning in the format patterns:
0#,.-;%¤’
To use these special characters as ordinary characters in your expression use the escape character.
Examples
Format pattern | Number | Result |
---|---|---|
{0000000000} | 9813756.198 | 0009813756 |
{##########} | 9813756.198 | 9813756 |
{#,###.##} | 9813756.198 | 9,813,756.2 |
{#,-##0.00} | -9813756.198 | 9,813,756.20 |
{-#,##0.00} | 9813756.198 | -9,813,756.20 |
{#,##0.00;-#,##0} | 9813756.198 | 9,813,756.20 |
{#,##0.00;-#,##0} | -9813756.198 | -9,813,756 |
{#,##0.## %} | 0.8 | 80 % |
{% #,##0.##} | 0.8 | % 80 |
{¤ #,##0.00} | 9813756.198 | $ 9,813,756.20 |
{#,##0.00 ¤} | 9813756.198 | 9,813,756.20 $ |
{#,##0.00 €} | 9813756.198 | 9,813,756.20 € |
{€ #,##0.00} | 9813756.198 | € 9,813,756.20 |
{‘#’#} | 123 | #123 |
Dates
In TSL, you can use date formats to change the appearance of dates, without changing the date behind the appearance. The date format you apply does not affect the actual value.
The date formats used in TSL are common Java 1.4 date formats. The most commonly used formatting symbols are listed below. For a complete documentation we refer to the online java documentation that is available at http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html.
The number of symbol letters you specify also determines the format. For example, if the “zz” pattern results in “PDT,” then the “zzzz” pattern generates “Pacific Daylight Time.” The following table summarizes these rules and symbols:
Symbol | Meaning | Number of symbols | |
---|---|---|---|
G | era designator | 1-3 >= 4 | abbreviated form, if one exists full form |
y | year | 1-4 | The minimum number of digits that is required, shorter numbers are padded with zeros |
M | month in year | 1-2 3 | number form text form |
d | day in month | 1-2 | The minimum number of digits that is required, shorter numbers are padded with zeros |
h | hour in am/pm (1-12) | 1-2 | The minimum number of digits that is required, shorter numbers are padded with zeros |
H | hour in day (0-23) | 1-2 | The minimum number of digits that is required, shorter numbers are padded with zeros |
m | minute in hour | 1-2 | The minimum number of digits that is required, shorter numbers are padded with zeros |
s | second in minute | 1-2 | The minimum number of digits that is required, shorter numbers are padded with zeros |
S | millisecond | 1-2 | The minimum number of digits that is required, shorter numbers are padded with zeros |
E | day in week | 1-3 >=4 | abbreviated form, if one exists full form |
D | day in year | 1-3 | The minimum number of digits that is required, shorter numbers are padded with zeros |
F | day of week in month | 1-2 | The minimum number of digits that is required, shorter numbers are padded with zeros |
w | week in year | 1-2 | The minimum number of digits that is required, shorter numbers are padded with zeros |
W | week in month | 1 | The minimum number of digits that is required, shorter numbers are padded with zeros |
a | am/pm marker | 1-3 >=4 | abbreviated form, if one exists full form |
k | hour in day (1-24) | 1-2 | The minimum number of digits that is required, shorter numbers are padded with zeros |
K | hour in am/pm (0-11) | 1-2 | The minimum number of digits that is required, shorter numbers are padded with zeros |
z | time zone | 1-3 >=4 | abbreviated form, if one exists full form |
‘ | escape for text |
These symbols are used to create a format pattern.
Examples
The given date and time are 04-08-2004 16:20:56 local time in the Central European Time Zone:
Format pattern | Result | Explanation |
---|---|---|
TODAY{dd-MM-yyyy} | 04-08-2004 | |
TODAY{E-MMM-yyyy} | Wed-Aug-2004 | |
TODAY{D} | 217 | Today is the 217-st day in the year 2004 |
TODAY{d} | 4 | Today is the 4-st day in the month August |
TODAY{w} | 32 | Today is the 32-st week in the year 2004 |
TODAY{W} | 1 | Today is the 1-st week in the month August |
TODAY{F} | 1 | Today is the 1-st Wednesday in the month August |
TODAY{EEEEEEEEEE} | Wednesday | Today is Wednesday |
TODAY{z} | CEST | The current time zone is CEST |
TODAY{zzzzz} | Central European Summer Time | The current time zone is Central European Summer Time |
TODAY{dd-MM-yyyy G ‘at’ zzz} | 04-08-2004 AD at CEST |