11. Шаблоны
11.1. Пример шаблона XML
<TESTLegalentityResponse xmlns="urn://test/legalentity/3.0">
<legalEntities search="{{xpath("//*[local-name() = 'search']")}}" requestId="{{xpath("//*[local-name() = 'requestId']")}}">
{{ sql("legalEntities", "select * from LegalEntity le, LegalEntityAddress lea, LegalEntityCEO lec where le.OGRN=lea.OGRN and le.OGRN=lec.OGRN and lea.dateTo is null and lec.dateTo is null and le.name like ?", "%" + xpath("//*[local-name() = 'search']") + "%") }}
{% for le in rows.legalEntities %}
<legalEntity>
<OGRN>{{le.ogrn}}</OGRN>
<INN>{{le.inn}}</INN>
<KPP>{{le.kpp}}</KPP>
<name>{{le.name}}</name>
<legalAddress>{{le.address}}</legalAddress>
<CEO>{{le.fio}}</CEO>
<CEO-history>
{{ sql("ceos", "select * from LegalEntityCEO where OGRN=? and dateTo is not null", le.ogrn) }}
{% for ceo in rows.ceos %}
<CEO from="{{ceo.datefrom}}" to="{{ceo.dateto}}" FIO="{{ceo.fio}}"/>
{% endfor %}
</CEO-history>
<address-history>
{{ sql("addresses", "select * from LegalEntityAddress where OGRN=? and dateTo is not null", le.ogrn) }}
{% for address in rows.addresses %}
<address from="{{address.datefrom}}" to="{{address.dateto}}" address="{{address.address}}"/>
{% endfor %}
</address-history>
</legalEntity>
{% endfor %}
</legalEntities>
</TESTLegalentityResponse>
11.2. Пример шаблона JSON
{
"legalEntities": {
"search": "{{ search }}",
"requestId": "{{ requestId }}",
"legalEntity": [
{{ sql("legalEntities", "select * from LegalEntity le, LegalEntityAddress lea, LegalEntityCEO lec where le.OGRN=lea.OGRN and le.OGRN=lec.OGRN and lea.dateTo is null and lec.dateTo is null and le.name like ?", "%" + search + "%") }}
{% for le in rows.legalEntities %}
{
"ogrn": "{{le.ogrn}}",
"inn": "{{le.inn}}",
"kpp": "{{le.kpp}}",
"name": "{{le.name}}",
"legalAddress": "{{le.address}}",
"ceo": "{{le.fio}}",
"ceohistory": { "ceo": [
{{ sql("ceos", "select * from LegalEntityCEO where OGRN=? and dateTo is not null", le.ogrn) }}
{% for ceo in rows.ceos %}
{ "from": "{{ceo.datefrom}}", "to": "{{ceo.dateto}}", "fio": "{{ceo.fio}}" }
{% if not loop.last %}
,
{% endif %}
{% endfor %}
]},
"addressHistory": { "address": [
{{ sql("addresses", "select * from LegalEntityAddress where OGRN=? and dateTo is not null", le.ogrn) }}
{% for address in rows.addresses %}
{ "from": "{{address.datefrom}}", "to": "{{address.dateto}}", "address": "{{address.address}}" }
{% if not loop.last %}
,
{% endif %}
{% endfor %}
]}
}
{% if not loop.last %}
,
{% endif %}
{% endfor %}
]
}
}