1 freemarker.template.process
<freemarker.template.process
language-tag='es-ES|en-GB|...'
number-format='0.####|...'
>
<template /> !
</freemarker.template.process>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Alanguage-tag | String | Language which will be used in the process phase to surpass the predefined regional configuration. For example, allows to set the configuration of the decimal number separator, the format in which the numbers will be showed. | |||
Anumber-format | String | Number format which will be used in the process phase to exceed the predefined regional configuration. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Etemplate | Object corresponding to the template. |
Returns | |
---|---|
Type | Description |
Object | Returns the resulting text of applying the template to the execution context. |
Creation and processing of a simple template.
<xsql-script name='sample_1'> <body> <set name='template'> <freemarker.template> <![CDATA[<html> <body> ${message} </body> </html>]]> </freemarker.template> </set> <set name='message'><string>Hello world!</string></set> <println><string.trim> <freemarker.template.process> <template/> </freemarker.template.process> </string.trim></println> </body> </xsql-script>
<html>
<body>
Hello world!
</body>
</html>
2 Environment layer
The settings of the environment variables influence in the behaviour of FreeMarker. Some configuration examples are: locale, number_format.
The default settings can be overwritten in a template instance. For example, if the regional configuration is set to "en_US", the regional configuration will be "en_US" in all the templates which use this configuration, except in the template where the regional configuration was explicitly specified in a different way.
For example, allows to set the character of decimal separator according the location ("."
in anglo-saxon context,
","
in european context).
It exist two ways to set a particular regional configuration in the transformation process:
- Using the attribute language-tag and number-format in the process function.
- Using directivas in the template code.
2.1 Attributes
The function freemarker.template.process dispose of the attributes language-tag and number-format which allows to exceed the regional configuration by default.
2.1.1 language-tag
The tag for the regional location is built with the language code and the region code separated by hyphen "-"
.
The language code are two or three lowercase letters which accomplish with the standard ISO 639. The region code (country) consists in two or three capital letters which accomplish with the standard ISO 3166, or three numbers which accomplish with the norm UN M.49.
Language | Region | Tag | ||
---|---|---|---|---|
Code | Description | Code | Description | Tag |
de | German | DE | Germany | de-DE |
es | Spanish | ES | Spain | es-ES |
fr | French | FR | France | fr-FR |
en | english | GB | Great Britain | en-GB |
en | english | US | United States | en-US |
2.1.2 number-format
Symbol | Location | Info |
---|---|---|
0 | Number | Digit |
# | Number | Digit, the zero is not showed |
. | Number | Decimal separator or monetary decimal separator |
- | Number | Minus |
, | Number | Group separator |
E | Number | Separates mantissa and exponent in scientific notation. It does not need to be cited in prefix or suffix |
; | Subpattern boundary | Separate the positive and negative subpatterns. |
% | Prefix or sufixx | Multiply by 100 and show as percentage |
\u2030 | Prefix or sufixx | Multiply by 1000 and show as value by thousand |
\¤ (\u00A4) | Prefix or sufixx | Currency sign, replaced by the currency sign. If it is duplicate, it is replaced by the international currency symbol. If it is present in a pattern, it is used the monetary decimal sepatared instead of the decimal separator. |
' | Prefix or sufixx | It is used to mention the special characters in a prefix or sufixx, for example, the formats "'#' #" 123 to "# 123". To create a single appointment, use two in a row: "# or''clock". |
Value | Pattern | Output | Info |
---|---|---|---|
123456.789 | ###,###.### | 123,456.789 | The numeral sign (#) denotes a digit, comma is a position marker for the grouping separator and the period is a position marker for the decimal separator. |
123456.789 | ###.## | 123456.79 | Tha value has three digits to the right of the decimal point, but the pattern has only two. The format methode handles this when rounding. |
123.78 | 000000.000 | 000123.780 | The pattern specifies the zeros at the beginning and at the end because the character 0 is used instead of the numeral sign (#) |
123456.789 | ###,###.### | 123,456.789 | The numeral sign (#) denotes a digit, the comma is a position marker for the grouping separator and the period is a position marker for the decimal separator. |
12345.67 | \u00A5###,###.### | ¥12,345.67 | The pattern specifies the currency sign for the japanese yen (¥) with the Unicode value 00A5 |
Example of use of language-tag attribute for European location for numbers.
<xsql-script> <body> <set name='taxbas_subject_exempt'><number>23.4</number></set> <set name='m_doc_template'><freemarker.template><![CDATA[ <sii:TaxBase>${taxbas_subject_exempt?string["0.000"]}</sii:TaxBase> ]]></freemarker.template></set> <println> <freemarker.template.process language-tag='it-IT'> <m_doc_template/> </freemarker.template.process> </println> </body> </xsql-script>
<sii:TaxBase>23,400</sii:TaxBase>
Example of use of number-format attribute for number format. Use of the mask "#.00" for formatting to two decimals. In the previous example in the template code itself, the variable had a specified mask.
${basimp_sujeta_exenta?string["0.000"]}
which we do not put in the following example or otherwise it would exceed the attribute.
<xsql-script> <body> <set name='basimp_sujeta_exenta'><number>23.4</number></set> <set name='m_doc_template'><freemarker.template><![CDATA[ <sii:TaxBase>${taxbas_subject_exempt}</sii:TaxBase> ]]></freemarker.template></set> <println> <freemarker.template.process language-tag='it-IT' number-format='#.00'> <m_doc_template/> </freemarker.template.process> </println> </body> </xsql-script>
<sii:TaxBase>23,40</sii:TaxBase>
2.2 Directivas
The grammar to set the directives and surpass the default regional settings is as follows:
<#setting locale="it_IT"> <#setting number_format="0.####">
Example of use of directives of anglo-saxon location for number formats.
<xsql-script> <body> <set name='basimp_sujeta_exenta'><number>23.4</number></set> <set name='m_doc_template'><freemarker.template><![CDATA[ <#setting locale='en_US'/> <sii:TaxBase>${taxbas_subject_exempt?string["0.000"]}</sii:TaxBase> ]]></freemarker.template></set> <println> <freemarker.template.process> <m_doc_template/> </freemarker.template.process> </println> </body> </xsql-script>
<sii:TaxBase>23.400</sii:TaxBase>
Example of use of directive of european location and four decimals for number format.
<xsql-script> <body> <set name='taxbas_subject_exempt'><number>23.4</number></set> <set name='m_doc_template'><freemarker.template><![CDATA[ <#setting locale='it_IT'/> <#setting number_format="#.0000"> <sii:TaxBase>${taxbas_subject_exempt}</sii:TaxBase> ]]></freemarker.template></set> <println> <freemarker.template.process> <m_doc_template/> </freemarker.template.process> </println> </body> </xsql-script>
<sii:TaxBase>23,4000</sii:TaxBase>