<?xml version="1.0" encoding="UTF-8"?>
<PcGts xmlns="http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15 http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15/pagecontent.xsd">
    <Metadata>
        <Creator>{{ metadata.creator }}</Creator>
        <Created>{{ metadata.created }}</Created>
        <LastChange>{{ metadata.created }}</LastChange>
    </Metadata>
    <Page imageFilename="{{ page.get('file_name') }}" imageWidth="{{ page.width }}" imageHeight="{{ page.height }}">
        <ReadingOrder>
            <OrderedGroup id='ro'>
            {%- for node in page recursive %}
            {%- if node.text %}
            <RegionRefIndexed regionRef="{{ node.label }}" index="{{ loop.index-1 }}"/>
            {%- else %}
            <OrderedGroupIndexed id="ro_{{ node.label }}" index="{{ loop.index-1 }}">{{ loop(node.children) }}
            </OrderedGroupIndexed>
            {%- endif %}
            {%- endfor %}
            </OrderedGroup>
        </ReadingOrder>
        {% if not page.has_regions() %} {# Page has no regions - put all lines in a big region that covers the entire page #}
        <TextRegion id="{{ page.label }}">
            <Coords points="{% for point in page.polygon %}{{ point|join(',') }}{% if not loop.last %} {% endif %}{% endfor %}" />
        {% endif %}
        {%- for node in page recursive %}
        {%- if is_text_line(node) %}
            <TextLine id="{{ node.label }}">
            <Coords points="{% for point in node.polygon %}{{ point|join(',') }}{% if not loop.last %} {% endif %}{% endfor %}" />
            {%- if node.children %}
            {%- for child in node.children %}
                <Word id="{{ child.label }}">
                    <Coords points="{% for point in child.polygon %}{{ point|join(',') }}{% if not loop.last %} {% endif %}{% endfor %}" />
                    <TextEquiv conf="{{ child.text_result.top_score() }}">
                        <Unicode>{{ xmlescape(child.text) }}</Unicode>
                    </TextEquiv>
                </Word>
            {%- endfor %}
            {%- else %}
            <TextEquiv conf="{{ node.text_result.top_score() }}">
                <Unicode>{{ xmlescape(node.text) }}</Unicode>
            </TextEquiv>
            {%-endif %}
            </TextLine>
        {%- else %}
        <TextRegion id="{{ node.label }}">
            <Coords points="{% for point in node.polygon %}{{ point|join(',') }}{% if not loop.last %} {% endif %}{% endfor %}" />{{ loop(node.children) }}
        </TextRegion>
        {%- endif %}
        {%- endfor %}
    {% if not page.has_regions() %}</TextRegion>{% endif %}  {# Closing tag for lines 21-24 #}
    </Page>
</PcGts>
