This methode allows to process a FreeMarker template object, applying the variables of the execution context.

1 freemarker.template.process

<freemarker.template.process
    language-tag='es-ES|en-GB|...'
    number-format='0.####|...'
>
    <template /> !
</freemarker.template.process>
Example

Creation and processing of a simple template.

Copy
<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.

Más información.

Ejemplos de tags
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

Special characters of numerical masks
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".

Building numerical masks
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

Example of use of language-tag attribute for European location for numbers.

Copy
<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

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.

Copy
${basimp_sujeta_exenta?string["0.000"]}

which we do not put in the following example or otherwise it would exceed the attribute.

Copy
<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:

Copy
<#setting locale="it_IT">
<#setting number_format="0.####">
Example

Example of use of directives of anglo-saxon location for number formats.

Copy
<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

Example of use of directive of european location and four decimals for number format.

Copy
<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>