view flys-artifacts/doc/conf/meta-data.xml @ 5257:46e984a3d576

Break long lines in FLYS statements.
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 11 Mar 2013 12:55:09 +0100
parents 908848b74d7e
children a75acd0d5fee
line wrap: on
line source
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<dc:template xmlns:dc="http://www.intevation.org/2011/Datacage">
<datacage>
  <dc:comment>
    Statement to load data from wsts.
  </dc:comment>
  <dc:macro name="SQL-wst_columns_statement">
    <dc:statement>
        SELECT wst_columns.id          AS prot_column_id,
               wst_columns.name        AS prot_column_name,
               wst_columns.position    AS prot_rel_pos,
               wst_columns.description AS info,
               wst_ranges.a            AS deffrom,
               wst_ranges.b            AS defto
        FROM wst_columns, wst_ranges
        WHERE wst_columns.wst_id = ${prot_id}
           AND wst_ranges.wst_column_id = wst_columns.id
           AND (${fromkm} BETWEEN wst_ranges.a AND wst_ranges.b
           OR ${tokm} BETWEEN wst_ranges.a AND wst_ranges.b
           OR wst_ranges.a BETWEEN ${fromkm} AND ${tokm}
           OR wst_ranges.b BETWEEN ${fromkm} AND ${tokm})
        ORDER by wst_columns.position
    </dc:statement>
  </dc:macro>

  <dc:comment>
    Load user specific distance information from artifact.
  </dc:comment>
  <dc:macro name="user-range">
    <dc:choose>
      <dc:when test="dc:contains($parameters, 'user-id')">
        <dc:context connection="user">
        <dc:statement>
          SELECT COALESCE(ld_mode, '')      AS ldm,
                 COALESCE(ld_locations, '') AS ldl,
                 COALESCE(ld_from, '')      AS ldf,
                 COALESCE(ld_to, '')        AS ldt
          FROM master_artifacts_range
          WHERE gid = CAST(${artifact-id} as uuid)
        </dc:statement>
        <dc:elements>
          <dc:variable name="fromkm" type="number" expr="dc:fromValue($ldm, $ldl, $ldf)"/>
          <dc:variable name="tokm" type="number" expr="dc:toValue($ldm, $ldl, $ldt)"/>
          <dc:macro-body/>
        </dc:elements>
        </dc:context>
      </dc:when>
      <dc:otherwise>
        <dc:variable name="fromkm" type="number" expr="dc:fromValue('', '', '')"/>
        <dc:variable name="tokm" type="number" expr="dc:toValue('', '', '')"/>
        <dc:macro-body/>
      </dc:otherwise>
    </dc:choose>
  </dc:macro>

  <dc:comment>
    System part. Load data for the given river.
  </dc:comment>
  <dc:macro name="load-system">
    <dc:context connection="system">
      <dc:statement>
        SELECT id AS river_id, name as river_name FROM rivers
        WHERE lower(name) LIKE lower(${river})
      </dc:statement>
      <dc:elements>

        <dc:comment>
          Base-data macros (mostly data imported from wst-files).
        </dc:comment>
        <dc:macro name="basedata_0">
          <dc:call-macro name="user-range">
            <dc:comment comment=" BASEDATA ---------------------------"/>
            <basedata>
              <dc:context connection="system">
                <dc:statement>
                  SELECT id          AS prot_id,
                         description AS prot_description
                  FROM wsts WHERE kind = 0 AND river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <basedata>
                    <dc:attribute name="name" value="${prot_description}"/>
                    <dc:context>
                      <dc:call-macro name="SQL-wst_columns_statement"/>
                      <dc:elements>
                        <column>
                          <dc:attribute name="name" value="${prot_column_name}"/>
                          <dc:attribute name="ids" value="base_data-wstv-${prot_rel_pos}-${prot_id}"/>
                          <dc:attribute name="factory" value="staticwkms"/>
                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
                        </column>
                      </dc:elements>
                    </dc:context>
                  </basedata>
                </dc:elements>
              </dc:context>
            </basedata>
          </dc:call-macro>
        </dc:macro>

        <dc:macro name="basedata_0_wq">
          <dc:call-macro name="user-range">
            <dc:comment comment=" BASEDATA ---------------------------"/>
            <basedata>
              <dc:context connection="system">
                <dc:statement>
                  SELECT id          AS prot_id,
                         description AS prot_description
                  FROM wsts WHERE kind = 0 AND river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <basedata>
                    <dc:attribute name="name" value="${prot_description}"/>
                    <dc:context>
                      <dc:call-macro name="SQL-wst_columns_statement"/>
                      <dc:elements>
                        <column>
                          <dc:attribute name="name" value="${prot_column_name}"/>
                          <dc:attribute name="ids" value="base_data-wstv-${prot_rel_pos}-${prot_id}"/>
                          <dc:attribute name="factory" value="wqinterpol"/>
                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
                        </column>
                      </dc:elements>
                    </dc:context>
                  </basedata>
                </dc:elements>
              </dc:context>
            </basedata>
          </dc:call-macro>
        </dc:macro>

        <dc:macro name="basedata_1_additionals_marks">
          <dc:call-macro name="user-range">
            <dc:comment comment=".ZUS -------------------------------"/>
            <additionals>
              <dc:context connection="system">
                <dc:statement>
                  SELECT id          AS prot_id,
                         description AS prot_description
                  FROM wsts WHERE kind = 1 AND river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <additional>
                    <dc:attribute name="name" value="${prot_description}"/>
                    <dc:context>
                      <dc:call-macro name="SQL-wst_columns_statement"/>
                      <dc:elements>
                        <column>
                          <dc:attribute name="name" value="${prot_column_name}"/>
                          <dc:attribute name="ids" value="additionalsmarks-wstv-${prot_rel_pos}-${prot_id}"/>
                          <dc:attribute name="factory" value="staticwkms"/>
                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
                        </column>
                      </dc:elements>
                    </dc:context>
                  </additional>
                </dc:elements>
              </dc:context>
            </additionals>
          </dc:call-macro>
        </dc:macro>

        <dc:macro name="basedata_1_additionals">
          <dc:call-macro name="user-range">
            <dc:comment comment=".ZUS -------------------------------"/>
            <additionals>
              <dc:context connection="system">
                <dc:statement>
                  SELECT id          AS prot_id,
                         description AS prot_description
                  FROM wsts WHERE kind = 1 AND river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <additional>
                    <dc:attribute name="name" value="${prot_description}"/>
                    <dc:context>
                      <dc:call-macro name="SQL-wst_columns_statement"/>
                      <dc:elements>
                        <column>
                          <dc:attribute name="name" value="${prot_column_name}"/>
                          <dc:attribute name="ids" value="additionals-wstv-${prot_rel_pos}-${prot_id}"/>
                          <dc:attribute name="factory" value="staticwkms"/>
                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
                        </column>
                      </dc:elements>
                    </dc:context>
                  </additional>
                </dc:elements>
              </dc:context>
            </additionals>
          </dc:call-macro>
        </dc:macro>

        <dc:macro name="basedata_1_additionals-relative_point">
          <dc:call-macro name="user-range">
            <dc:comment comment=".ZUS -------------------------------"/>
            <additionals>
              <dc:context connection="system">
                <dc:statement>
                  SELECT id          AS prot_id,
                         description AS prot_description
                  FROM wsts WHERE kind = 1 AND river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <relativepoint>
                    <dc:attribute name="name" value="${prot_description}"/>
                    <dc:context>
                      <dc:call-macro name="SQL-wst_columns_statement"/>
                      <dc:elements>
                        <column>
                          <dc:attribute name="name" value="${prot_column_name}"/>
                          <dc:attribute name="ids" value="additionals-wstv-${prot_rel_pos}-${prot_id}"/>
                          <dc:attribute name="factory" value="staticwkms"/>
                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
                        </column>
                      </dc:elements>
                    </dc:context>
                  </relativepoint>
                </dc:elements>
              </dc:context>
            </additionals>
          </dc:call-macro>
        </dc:macro>

        <dc:macro name="basedata_2_fixations_wst">
          <dc:call-macro name="user-range">
            <fixations>
              <dc:context connection="system">
                <dc:statement>
                  SELECT id          AS prot_id,
                         description AS prot_description
                  FROM wsts WHERE kind = 2 AND river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <fixation>
                    <dc:attribute name="name" value="${prot_description}"/>
                    <!--dc:attribute name="ids" value="fixations-wstv-A-${prot_id}"/-->
                    <dc:context>
                      <dc:call-macro name="SQL-wst_columns_statement"/>
                      <dc:elements>
                        <column>
                          <dc:attribute name="name" value="${prot_column_name}"/>
                          <dc:attribute name="ids" value="fixations-wstv-${prot_rel_pos}-${prot_id}"/>
                          <dc:attribute name="factory" value="wqinterpol"/>
                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
                        </column>
                      </dc:elements>
                    </dc:context>
                  </fixation>
                </dc:elements>
              </dc:context>
            </fixations>
          </dc:call-macro>
        </dc:macro>

        <dc:macro name="basedata_2_fixations_wqkms">
          <dc:call-macro name="user-range">
            <fixations>
              <dc:context connection="system">
                <dc:statement>
                  SELECT id          AS prot_id,
                         description AS prot_description
                  FROM wsts WHERE kind = 2 AND river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <fixation>
                    <dc:attribute name="name" value="${prot_description}"/>
                    <dc:context>
                      <dc:call-macro name="SQL-wst_columns_statement"/>
                      <dc:elements>
                        <column>
                          <dc:attribute name="name" value="${prot_column_name}"/>
                          <dc:attribute name="ids" value="fixations-wstv-${prot_rel_pos}-${prot_id}"/>
                          <dc:attribute name="factory" value="wqinterpol"/>
                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
                        </column>
                      </dc:elements>
                    </dc:context>
                  </fixation>
                </dc:elements>
              </dc:context>
            </fixations>
          </dc:call-macro>
        </dc:macro>

        <dc:macro name="basedata_2_fixations">
          <dc:call-macro name="user-range">
            <fixations>
              <dc:context connection="system">
                <dc:statement>
                  SELECT id          AS prot_id,
                         description AS prot_description
                  FROM wsts WHERE kind = 2 AND river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <fixation>
                    <dc:attribute name="name" value="${prot_description}"/>
                    <dc:context>
                      <dc:call-macro name="SQL-wst_columns_statement"/>
                      <dc:elements>
                        <column>
                          <dc:attribute name="name" value="${prot_column_name}"/>
                          <dc:attribute name="ids" value="fixations-wstv-${prot_rel_pos}-${prot_id}"/>
                          <dc:attribute name="factory" value="staticwkms"/>
                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
                        </column>
                      </dc:elements>
                    </dc:context>
                  </fixation>
                </dc:elements>
              </dc:context>
            </fixations>
          </dc:call-macro>
        </dc:macro>

        <dc:macro name="basedata_2_fixations_relative_point">
          <dc:call-macro name="user-range">
            <fixations>
              <dc:context connection="system">
                <dc:statement>
                  SELECT id          AS prot_id,
                         description AS prot_description
                  FROM wsts WHERE kind = 2 AND river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <relativepoint>
                    <dc:attribute name="name" value="${prot_description}"/>
                    <dc:context>
                      <dc:call-macro name="SQL-wst_columns_statement"/>
                      <dc:elements>
                        <column>
                          <dc:attribute name="name" value="${prot_column_name}"/>
                          <dc:attribute name="ids" value="fixations-wstv-${prot_rel_pos}-${prot_id}"/>
                          <dc:attribute name="factory" value="staticwkms"/>
                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
                        </column>
                      </dc:elements>
                    </dc:context>
                  </relativepoint>
                </dc:elements>
              </dc:context>
            </fixations>
          </dc:call-macro>
        </dc:macro>

        <dc:macro name="basedata_3_officials">
          <dc:call-macro name="user-range">
            <dc:comment comment=".wst -------------------------------"/>
            <officiallines>
              <dc:context connection="system">
                <dc:statement>
                  SELECT id          AS prot_id,
                         description AS prot_description
                  FROM wsts WHERE kind = 3 AND river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <official>
                    <dc:attribute name="name" value="${prot_description}"/>
                    <dc:context>
                      <dc:call-macro name="SQL-wst_columns_statement"/>
                      <dc:elements>
                        <column>
                          <dc:attribute name="name" value="${prot_column_name}"/>
                          <dc:attribute name="ids" value="additionals-wstv-${prot_rel_pos}-${prot_id}"/>
                          <dc:attribute name="factory" value="staticwqkms"/>
                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
                        </column>
                      </dc:elements>
                    </dc:context>
                  </official>
                </dc:elements>
              </dc:context>
            </officiallines>
          </dc:call-macro>
        </dc:macro>

        <dc:macro name="basedata_4_heightmarks-points-relative_points">
          <dc:call-macro name="user-range">
            <heightmarks>
              <dc:context connection="system">
                <dc:statement>
                  SELECT id          AS prot_id,
                         description AS prot_description
                  FROM wsts WHERE kind = 4 AND river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <relativepoint>
                    <dc:attribute name="name" value="${prot_description}"/>
                    <dc:context>
                      <dc:call-macro name="SQL-wst_columns_statement"/>
                      <dc:elements>
                        <column>
                          <dc:attribute name="name" value="${prot_column_name}"/>
                          <dc:attribute name="ids" value="heightmarks_points-wstv-${prot_rel_pos}-${prot_id}"/>
                          <dc:attribute name="factory" value="staticwkms"/>
                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
                        </column>
                      </dc:elements>
                    </dc:context>
                  </relativepoint>
                </dc:elements>
              </dc:context>
            </heightmarks>
          </dc:call-macro>
        </dc:macro>

        <dc:macro name="basedata_4_heightmarks-points">
          <dc:call-macro name="user-range">
            <heightmarks>
              <dc:context connection="system">
                <dc:statement>
                  SELECT id          AS prot_id,
                         description AS prot_description
                  FROM wsts WHERE kind = 4 AND river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <heightmark>
                    <dc:attribute name="name" value="${prot_description}"/>
                    <dc:context>
                      <dc:call-macro name="SQL-wst_columns_statement"/>
                      <dc:elements>
                        <column>
                          <dc:attribute name="name" value="${prot_column_name}"/>
                          <dc:attribute name="ids" value="heightmarks_points-wstv-${prot_rel_pos}-${prot_id}"/>
                          <dc:attribute name="factory" value="staticwkms"/>
                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
                        </column>
                      </dc:elements>
                    </dc:context>
                  </heightmark>
                </dc:elements>
              </dc:context>
            </heightmarks>
          </dc:call-macro>
        </dc:macro>

        <dc:macro name="basedata_4_heightmarks-wq">
          <dc:call-macro name="user-range">
            <heightmarks>
              <dc:context connection="system">
                <dc:statement>
                  SELECT id          AS prot_id,
                         description AS prot_description
                  FROM wsts WHERE kind = 4 AND river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <heightmark>
                    <dc:attribute name="name" value="${prot_description}"/>
                    <dc:context>
                      <dc:call-macro name="SQL-wst_columns_statement"/>
                      <dc:elements>
                        <column>
                          <dc:attribute name="name" value="${prot_column_name}"/>
                          <dc:attribute name="ids" value="heightmarks_annotations-wstv-${prot_rel_pos}-${prot_id}"/>
                          <dc:attribute name="factory" value="wqinterpol"/>
                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
                        </column>
                      </dc:elements>
                    </dc:context>
                  </heightmark>
                </dc:elements>
              </dc:context>
            </heightmarks>
          </dc:call-macro>
        </dc:macro>

        <dc:macro name="basedata_5_flood-protections_relative_points">
          <dc:call-macro name="user-range">
            <flood_protections>
              <dc:attribute name="id" value="flood-protections-${river_id}"/>
              <dc:context connection="system">
                <dc:statement>
                  SELECT id          AS prot_id,
                         description AS prot_description
                  FROM wsts WHERE kind = 5 AND river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <relativepoint>
                    <dc:attribute name="name" value="${prot_description}"/>
                    <dc:attribute name="db-id" value="${prot_id}"/>
                    <dc:attribute name="factory" value="staticwkms"/>
                    <columns>
                      <dc:context>
                        <dc:call-macro name="SQL-wst_columns_statement"/>
                        <dc:elements>
                          <column>
                            <dc:attribute name="name" value="${prot_column_name}"/>
                            <dc:attribute name="ids" value="flood_protection-wstv-${prot_rel_pos}-${prot_id}"/>
                            <dc:attribute name="factory" value="staticwkms"/>
                            <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
                          </column>
                        </dc:elements>
                      </dc:context>
                    </columns>
                  </relativepoint>
                </dc:elements>
              </dc:context>
            </flood_protections>
          </dc:call-macro>
        </dc:macro>

        <dc:macro name="basedata_5_flood-protections">
          <dc:call-macro name="user-range">
            <flood_protections>
              <dc:attribute name="id" value="flood-protections-${river_id}"/>
              <dc:context connection="system">
                <dc:statement>
                  SELECT id          AS prot_id,
                         description AS prot_description
                  FROM wsts WHERE kind = 5 AND river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <flood_protection>
                    <dc:attribute name="name" value="${prot_description}"/>
                    <dc:attribute name="db-id" value="${prot_id}"/>
                    <dc:attribute name="factory" value="staticwkms"/>
                    <dc:context>
                      <dc:call-macro name="SQL-wst_columns_statement"/>
                      <dc:elements>
                        <column>
                          <dc:attribute name="name" value="${prot_column_name}"/>
                          <dc:attribute name="ids" value="flood_protection-wstv-${prot_rel_pos}-${prot_id}"/>
                          <dc:attribute name="factory" value="staticwkms"/>
                          <dc:attribute name="info" value="${info} [km ${deffrom} - ${defto}]"/>
                        </column>
                      </dc:elements>
                    </dc:context>
                  </flood_protection>
                </dc:elements>
              </dc:context>
            </flood_protections>
          </dc:call-macro>
        </dc:macro>

        <dc:macro name="mainvalues">
          <mainvalue>
            <dc:attribute name="factory" value="mainvalue"/>
            <dc:attribute name="ids"     value="${river_id}"/>
          </mainvalue>
          <wmainvalue>
            <dc:attribute name="factory" value="mainvalue"/>
            <dc:attribute name="ids"     value="${river_id}:w"/>
          </wmainvalue>
          <qmainvalue>
            <dc:attribute name="factory" value="mainvalue"/>
            <dc:attribute name="ids"     value="${river_id}:q"/>
          </qmainvalue>
        </dc:macro>

        <dc:macro name="qsectors">
          <qsector>
            <dc:attribute name="factory" value="qsectors"/>
            <dc:attribute name="ids"     value="${river_id}"/>
          </qsector>
        </dc:macro>

        <dc:macro name="annotations">
          <annotation>
            <dc:attribute name="factory" value="annotations"/>
            <dc:attribute name="ids"     value="${river_id}"/>
          </annotation>
        </dc:macro>

        <dc:macro name="annotations_per_type">
          <annotations>
            <dc:context>
              <annotation>
                <dc:attribute name="name"    value="all_annotations"/>
                <dc:attribute name="factory" value="annotations"/>
                <dc:attribute name="ids"     value="${river_id}"/>
              </annotation>
              <dc:statement>
                SELECT id          AS anno_id,
                       name AS anno_description
                FROM annotation_types
              </dc:statement>
              <dc:elements>
                <annotation>
                  <dc:attribute name="name"    value="${anno_description}"/>
                  <dc:attribute name="factory" value="annotations"/>
                  <dc:attribute name="ids"     value="${river_id}:${anno_description}"/>
                </annotation>
             </dc:elements>
            </dc:context>
          </annotations>
        </dc:macro>

        <dc:macro name="cross_sections">
          <dc:call-macro name="user-range">
            <cross_sections>
              <dc:attribute name="id" value="flood-protections-${river_id}"/>
              <dc:context connection="system">
                <dc:statement>
                  SELECT DISTINCT
                         cs.id          AS prot_id,
                         cs.description AS prot_description
                  FROM cross_sections cs
                    JOIN cross_section_lines csl ON csl.cross_section_id = cs.id
                  WHERE cs.river_id = ${river_id}
                    AND csl.km BETWEEN ${fromkm} AND ${tokm}
                </dc:statement>
                <dc:elements>
                  <cross_section>
                    <dc:attribute name="name" value="${prot_description}"/>
                    <dc:attribute name="ids" value="${prot_id}"/>
                    <dc:attribute name="factory" value="crosssections"/>
                  </cross_section>
                </dc:elements>
              </dc:context>
            </cross_sections>
          </dc:call-macro>
        </dc:macro>

        <dc:macro name="hyks">
          <dc:call-macro name="user-range">
            <hyks>
              <dc:attribute name="id" value="hyk-${river_id}"/>
              <dc:context connection="system">
                <dc:statement>
                  SELECT DISTINCT
                         h.id          AS hyk_id,
                         h.description AS hyk_description
                  FROM hyks h
                    JOIN hyk_entries he ON he.hyk_id = h.id
                  WHERE river_id = ${river_id}
                    AND he.km BETWEEN ${fromkm} AND ${tokm}
                </dc:statement>
                <dc:elements>
                  <hyk>
                    <dc:attribute name="name" value="${hyk_description}"/>
                    <dc:attribute name="ids" value="${hyk_id}"/>
                    <dc:attribute name="factory" value="hyk"/>
                  </hyk>
                </dc:elements>
              </dc:context>
            </hyks>
          </dc:call-macro>
        </dc:macro>

        <dc:macro name="flow_velocity_measurements">
          <dc:call-macro name="user-range">
            <flowvelocitymeasurement>
            <dc:context connection="system">
                <dc:statement>
                  SELECT id          AS fvmid,
                         description AS fvmd
                  FROM flow_velocity_measurements WHERE river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <flow_velocity_measurement>
                    <dc:attribute name="name" value="${fvmd}"/>
                    <dc:attribute name="ids" value="${fvmid}"/>
                    <dc:attribute name="factory" value="flowvelocity"/>
                    <dc:context>
                        <dc:statement>
                                SELECT id, description, station, datetime, v, w, q
                                FROM flow_velocity_measure_values
                                WHERE measurements_id = ${fvmid}
                                  AND station BETWEEN ${fromkm} AND ${tokm}
                        </dc:statement>
                        <dc:elements>
                           <measurement_value>
                             <dc:attribute name="name" value="${id}-${description}-${station}-${datetime}"/>
                             <dc:attribute name="ids" value="${id}"/>
                             <dc:attribute name="factory" value="flowvelocity"/>
                           </measurement_value>
                         </dc:elements>
                    </dc:context>
                  </flow_velocity_measurement>
              </dc:elements>
          </dc:context>
          </flowvelocitymeasurement>
        </dc:call-macro>
        </dc:macro>

        <dc:macro name="sounding-width">
          <soundings_width>
            <dc:context>
              <dc:statement>
                  SELECT id          AS bedh_id,
                         year        AS bedh_year,
                         description AS bedh_descr
                  FROM bed_height_single WHERE river_id = ${river_id}
              </dc:statement>
              <dc:elements>
                <height>
                  <dc:attribute name="factory" value="bedheight"/>
                  <dc:attribute name="ids" value="bedheight-singlevalues-${bedh_id}-${bedh_year}"/>
                  <dc:attribute name="description" value="${bedh_descr}"/>
                </height>
              </dc:elements>
            </dc:context>
          </soundings_width>
        </dc:macro>

        <dc:macro name="longitudinal-section-prototype">
          <dc:call-macro name="basedata_0"/>
          <dc:call-macro name="basedata_1_additionals"/>
          <dc:comment comment=" FIXATIONS ---------------------------"/>
          <dc:call-macro name="basedata_2_fixations"/>
          <dc:comment comment=" HOEHENMARKEN ---------------------------"/>
          <dc:call-macro name="basedata_4_heightmarks-points"/>
          <dc:comment comment=" AMTL LINIEN  ---------------------------"/>
          <dc:call-macro name="basedata_3_officials"/>
          <dc:call-macro name="basedata_5_flood-protections"/>
          <dc:call-macro name="annotations_per_type"/>
        </dc:macro>

        <dc:comment>
        + River-Node
        </dc:comment>
        <river>
          <dc:attribute name="name" value="${river_name}"/>

          <dc:choose>
            <dc:when test="dc:contains($parameters, 'recommended')">
               <dc:comment>
                  Recommendations (client shall load immediately).
               </dc:comment>
               <dc:if test="dc:contains($artifact-outs, 'w_differences') or (dc:contains($artifact-outs, 'discharge_longitudinal_section'))">
                 <dc:call-macro name="annotations"/>
               </dc:if>
               <dc:if test="dc:contains($artifact-outs, 'cross_section')">
                 <dc:call-macro name="cross_sections"/>
                 <dc:call-macro name="hyks"/>
               </dc:if>
               <dc:if test="dc:contains($artifact-outs, 'computed_discharge_curve')">
                 <dc:call-macro name="mainvalues"/>
               </dc:if>
               <dc:if test="dc:contains($artifact-outs, 'duration_curve')">
                 <dc:call-macro name="mainvalues"/>
               </dc:if>
               <dc:if test="dc:contains($artifact-outs, 'reference_curve')">
                 <dc:call-macro name="annotations"/>
                 <dc:call-macro name="mainvalues"/>
               </dc:if>
               <dc:if test="dc:contains($artifact-outs, 'fix_wq_curve')">
                 <dc:call-macro name="qsectors"/>
               </dc:if>
               <dc:if test="dc:contains($artifact-outs, 'longitudinal_section')">
                 <dc:call-macro name="annotations"/>
               </dc:if>
               <dc:if test="dc:contains($artifact-outs, 'fix_longitudinal_section_curve')">
                 <dc:call-macro name="annotations"/>
               </dc:if>
               <dc:if test="dc:contains($artifact-outs, 'bed_difference_epoch')">
                 <dc:call-macro name="annotations"/>
               </dc:if>
               <dc:if test="dc:contains($artifact-outs, 'bed_difference_year')">
                 <dc:call-macro name="annotations"/>
               </dc:if>
               <dc:if test="dc:contains($artifact-outs, 'bed_difference_height_year')">
                 <dc:call-macro name="annotations"/>
               </dc:if>
               <dc:if test="dc:contains($artifact-outs, 'flow_velocity')">
                 <dc:call-macro name="annotations"/>
               </dc:if>
            </dc:when>
            <dc:otherwise>
              <dc:comment>
                 Non - Recommendations.
              </dc:comment>
              <dc:if test="dc:contains($artifact-outs, 'cross_section')">
                 <dc:call-macro name="basedata_0"/>
                 <dc:call-macro name="basedata_1_additionals"/>
                 <dc:call-macro name="basedata_2_fixations"/>
                 <dc:call-macro name="basedata_3_officials"/>
                 <dc:call-macro name="basedata_4_heightmarks-points"/>
                 <dc:call-macro name="cross_sections"/>
                 <dc:call-macro name="hyks"/>
              </dc:if>
              <!--dc:if test="dc:contains($artifact-outs, 'computed_discharge_curve')">
                 <dc:call-macro name="basedata_0_wq"/>
                 <dc:call-macro name="basedata_4_heightmarks-wq"/>
              </dc:if-->
              <dc:if test="dc:contains($artifact-outs, 'longitudinal_section') or (dc:contains($artifact-outs, 'w_differences')) or (dc:contains($artifact-outs, 'discharge_longitudinal_section'))">
                  <dc:call-macro name="longitudinal-section-prototype"/>
              </dc:if>
              <dc:if test="dc:contains($artifact-outs, 'duration_curve')">
                  <dc:call-macro name="mainvalues"/>
                  <dc:call-macro name="basedata_2_fixations_relative_point"/>
                  <dc:call-macro name="basedata_4_heightmarks-points-relative_points"/>
                  <dc:call-macro name="basedata_5_flood-protections_relative_points"/>
              </dc:if>
              <dc:if test="dc:contains($artifact-outs, 'reference_curve')">
                <dc:call-macro name="annotations"/>
                <!--dc:call-macro name="basedata_0"/-->
                <dc:call-macro name="basedata_1_additionals-relative_point"/>
                <dc:comment comment=" FIXATIONS ---------------------------"/>
                <dc:call-macro name="basedata_2_fixations_relative_point"/>
                <dc:comment comment=" HOEHENMARKEN ---------------------------"/>
                <dc:call-macro name="basedata_4_heightmarks-points-relative_points"/>
                <dc:call-macro name="basedata_5_flood-protections_relative_points"/>
              </dc:if>
              <dc:if test="dc:contains($artifact-outs, 'fix_wq_curve')">
                <dc:call-macro name="basedata_0_wq"/>
                <dc:call-macro name="basedata_1_additionals_marks"/>
                <dc:call-macro name="basedata_2_fixations_wqkms"/>
                <dc:call-macro name="basedata_3_officials"/>
                <dc:call-macro name="basedata_4_heightmarks-points"/>
                <dc:call-macro name="basedata_5_flood-protections_relative_points"/>
              </dc:if>
              <dc:if test="dc:contains($artifact-outs, 'fix_deltawt_curve')">
              </dc:if>
              <dc:if test="dc:contains($artifact-outs, 'fix_longitudinal_section_curve')">
                <dc:call-macro name="annotations"/>
              </dc:if>
              <dc:if test="dc:contains($artifact-outs, 'map')">
                 <map>
                   <dc:call-macro name="flood-map-complete"/>
                 </map>
              </dc:if>
              <dc:if test="dc:contains($artifact-outs, 'flow_velocity')">
                <dc:call-macro name="annotations"/>
                <dc:call-macro name="flow_velocity_measurements"/>
              </dc:if>
              <dc:comment>
                MINFO bedheight middle
              </dc:comment>
              <dc:if test="dc:contains($artifact-outs, 'bedheight_middle')">
                <dc:call-macro name="sounding-width"/>
              </dc:if>
             <dc:comment comment="--- non-recommendations---"/>
            </dc:otherwise>
          </dc:choose>


          <dc:if test="dc:contains($artifact-outs, 'waterlevels')">

            <!-- base data -->
            <dc:call-macro name="basedata_0"/>

            <!-- extra-longitudinal-sections -->
            <dc:call-macro name="basedata_1_additionals"/>

            <!-- fixations -->
            <dc:call-macro name="basedata_2_fixations"/>

            <!-- flood water marks-->
            <dc:call-macro name="basedata_4_heightmarks-points"/>

            <!-- flood protection -->
            <dc:call-macro name="basedata_5_flood-protections"/>

          </dc:if>
          <dc:if test="dc:contains($artifact-outs, 'computed_discharge_curve') and (dc:contains($parameters, 'recommended'))">
                <!--dc:call-macro name="basedata_2_fixations_wst"/-->
          </dc:if>

          <dc:if test="dc:contains($artifact-outs, 'computed_discharge_curve') and not (dc:contains($parameters, 'recommended'))">
              <discharge_table_nn>
                <discharge_table_gauge>
                  <dc:context>
                    <dc:statement>
                      SELECT id   AS gauge_id,
                             name AS gauge_name
                      FROM gauges WHERE river_id = ${river_id}
                    </dc:statement>
                    <dc:elements>
                      <gauge>
                        <dc:attribute name="name" value="${gauge_name}"/>
                        <dc:attribute name="db-id" value="${gauge_id}"/>
                        <dc:attribute name="factory" value="gaugedischarge"/>
                        <dc:attribute name="from" value="${g_start}"/>
                        <dc:attribute name="to" value="${g_stop}"/>
                        <dc:attribute name="ids" value="${gauge_name}"/>
                      </gauge>
                      <!--
                      <gauge>
                        <dc:attribute name="name" value="${gauge_name}"/>
                        <dc:attribute name="db-id" value="${gauge_id}"/>
                        <dc:context>
                          <dc:statement>
                            SELECT description   AS gauge_desc,
                                   d.id          AS discharge_id,
                                   ti.start_time AS g_start,
                                   ti.stop_time  AS g_stop
                            FROM discharge_tables d JOIN time_intervals ti
                            ON d.time_interval_id = ti.id
                            WHERE d.gauge_id = ${gauge_id} AND d.kind = 1
                          </dc:statement>
                          <dc:elements>
                            <historical>
                              <dc:attribute name="name" value="${gauge_desc}"/>
                              <dc:attribute name="factory" value="gaugedischarge"/>
                              <dc:attribute name="from" value="${g_start}"/>
                              <dc:attribute name="to" value="${g_stop}"/>
                              <dc:attribute name="ids" value="${discharge_id}-${g_start}-${g_stop}"/>
                            </historical>
                          </dc:elements>
                        </dc:context>
                      </gauge>
                      -->
                    </dc:elements>
                  </dc:context>
                </discharge_table_gauge>

              </discharge_table_nn>

            <dc:call-macro name="basedata_2_fixations_wst"/>

            <dc:call-macro name="basedata_5_flood-protections"/>

            <!-- former waterlevels -->
            <dc:call-macro name="basedata_0"/>

            <dc:call-macro name="basedata_1_additionals"/>

            <!-- former flood-water-marks -->
            <dc:call-macro name="basedata_4_heightmarks-points"/>
              <computed_discharge_curve>
                <dc:call-macro name="mainvalues"/>
              </computed_discharge_curve>
          </dc:if>

          <dc:if test="dc:contains($artifact-outs, 'fix_wq_curve') and not (dc:contains($parameters, 'recommended'))">
              <discharge_table_nn>
                <discharge_table_gauge>
                  <dc:context>
                    <dc:statement>
                      SELECT id   AS gauge_id,
                             name AS gauge_name
                      FROM gauges WHERE river_id = ${river_id}
                    </dc:statement>
                    <dc:elements>
                      <gauge>
                        <dc:attribute name="name" value="${gauge_name}"/>
                        <dc:attribute name="db-id" value="${gauge_id}"/>
                        <dc:attribute name="factory" value="gaugedischarge"/>
                        <dc:attribute name="from" value="${g_start}"/>
                        <dc:attribute name="to" value="${g_stop}"/>
                        <dc:attribute name="ids" value="${gauge_name}"/>
                      </gauge>
                    </dc:elements>
                  </dc:context>
                </discharge_table_gauge>
              </discharge_table_nn>
          </dc:if>

          <dc:if test="dc:contains($artifact-outs, 'floodmap')">
              <floodmap>
              <dc:choose>
                  <dc:when test="dc:contains($parameters, 'recommended')">
                    <dc:call-macro name="flood-map-recommended"/>
                  </dc:when>
                  <dc:when test="dc:contains($parameters, 'dem')">
                    <dc:call-macro name="flood-map-dem"/>
                  </dc:when>
                  <dc:otherwise>
                    <dc:call-macro name="flood-map-complete"/>
                  </dc:otherwise>
              </dc:choose>
              </floodmap>
              <dc:macro name="flood-map-recommended">
                <dc:comment>
                   FIXME: Following two macros look identical to me.
                </dc:comment>
                  <kilometrage>
                      <riveraxis>
                          <dc:attribute name="factory" value="riveraxis"/>
                          <dc:attribute name="ids" value="${river_id}"/>
                      </riveraxis>
                  </kilometrage>
                  <rastermap>
                      <background>
                          <dc:attribute name="factory" value="wmsbackground"/>
                          <dc:attribute name="ids" value="${river_id}"/>
                      </background>
                  </rastermap>
              </dc:macro>
              <dc:macro name="flood-map-dem">
                <dems>
                  <dc:context>
                    <dc:statement>
                      SELECT d.id    AS dem_id,
                             r.a     AS dem_lower,
                             r.b     AS dem_upper,
                             d.name  AS name,
                             d.projection || ' | ' || t.start || ' - ' || t.stop AS info
                             FROM dem d
                             JOIN ranges r ON d.range_id r.id
                             JOIN time_intervals t ON d.time_interval_id t.id
                             WHERE river_id = ${river_id}
                    </dc:statement>
                    <dc:elements>
                        <dem>
                          <dc:attribute name="factory" value="demfactory"/>
                          <dc:attribute name="ids" value="${dem_id}"/>
                          <dc:attribute name="name" value="${name}"/>
                          <dc:attribute name="info" value="${info}"/>
                        </dem>
                    </dc:elements>
                  </dc:context>
                </dems>
              </dc:macro>
              <dc:macro name="flood-map-km">
                <dc:context>
                  <dc:statement>
                    SELECT count(*) as km_exists
                    FROM river_axes_km WHERE river_id = ${river_id}
                  </dc:statement>
                   <dc:elements>
                    <dc:if test="$km_exists>0">
                      <km>
                        <dc:attribute name="factory" value="wmskmfactory"/>
                        <dc:attribute name="ids" value="${river_id}"/>
                      </km>
                    </dc:if>
                  </dc:elements>
                </dc:context>
              </dc:macro>
              <dc:macro name="flood-map-qps">
                <dc:context>
                  <dc:statement>
                    SELECT count(*) as km_exists
                    FROM cross_section_tracks WHERE river_id = ${river_id}
                  </dc:statement>
                   <dc:elements>
                    <dc:if test="$km_exists>0">
                      <qps>
                        <dc:attribute name="factory" value="wmsqpsfactory"/>
                        <dc:attribute name="ids" value="${river_id}"/>
                      </qps>
                    </dc:if>
                  </dc:elements>
                </dc:context>
              </dc:macro>
              <dc:macro name="flood-map-hydr-boundaries">
                <hydr_boundaries_lines>
                  <dc:call-macro name="flood-map-hydr-boundaries-lines"/>
                </hydr_boundaries_lines>
                <hydr_boundaries_polygons>
                  <dc:call-macro name="flood-map-hydr-boundaries-poly"/>
                </hydr_boundaries_polygons>
              </dc:macro>
              <dc:macro name="flood-map-hydr-boundaries-lines">
                <bfg>
                  <dc:context>
                    <dc:statement>
                      SELECT count(*) as km_exists, name as name
                      FROM hydr_boundaries WHERE river_id = ${river_id} AND kind = 1 GROUP BY name
                    </dc:statement>
                     <dc:elements>
                      <dc:if test="$km_exists>0">
                        <hydrboundary>
                          <dc:attribute name="factory" value="wmshydrboundariesfactory"/>
                          <dc:attribute name="ids" value="${river_id};${name}"/>
                          <dc:attribute name="name" value="${name}"/>
                        </hydrboundary>
                      </dc:if>
                    </dc:elements>
                  </dc:context>
                </bfg>
                <land>
                  <dc:context>
                    <dc:statement>
                      SELECT count(*) as km_exists, name as name
                      FROM hydr_boundaries WHERE river_id = ${river_id} AND kind = 2 GROUP BY name
                    </dc:statement>
                     <dc:elements>
                      <dc:if test="$km_exists>0">
                        <hydrboundary>
                          <dc:attribute name="factory" value="wmshydrboundariesfactory"/>
                          <dc:attribute name="ids" value="${river_id};${name}"/>
                          <dc:attribute name="name" value="${name}"/>
                        </hydrboundary>
                      </dc:if>
                    </dc:elements>
                  </dc:context>
                </land>
              </dc:macro>
              <dc:macro name="flood-map-hydr-boundaries-poly">
                <bfg>
                  <dc:context>
                    <dc:statement>
                      SELECT count(*) as km_exists, name as name
                      FROM hydr_boundaries_poly WHERE river_id = ${river_id} AND kind = 1 GROUP BY name
                    </dc:statement>
                     <dc:elements>
                      <dc:if test="$km_exists>0">
                        <hws>
                          <dc:attribute name="factory" value="wmshydrboundariespolyfactory"/>
                          <dc:attribute name="ids" value="${river_id};${name}"/>
                          <dc:attribute name="name" value="${name}"/>
                        </hws>
                      </dc:if>
                    </dc:elements>
                  </dc:context>
                </bfg>
                <land>
                  <dc:context>
                    <dc:statement>
                      SELECT count(*) as km_exists, name as name
                      FROM hydr_boundaries_poly WHERE river_id = ${river_id} AND kind = 2 GROUP BY name
                    </dc:statement>
                     <dc:elements>
                      <dc:if test="$km_exists>0">
                        <hws>
                          <dc:attribute name="factory" value="wmshydrboundariespolyfactory"/>
                          <dc:attribute name="ids" value="${river_id};${name}"/>
                          <dc:attribute name="name" value="${name}"/>
                        </hws>
                      </dc:if>
                    </dc:elements>
                  </dc:context>
                </land>
              </dc:macro>
              <dc:macro name="flood-map-floodplain">
                <dc:context>
                  <dc:statement>
                    SELECT count(*) as km_exists
                    FROM floodplain WHERE river_id = ${river_id}
                  </dc:statement>
                   <dc:elements>
                    <dc:if test="$km_exists>0">
                      <floodplain>
                        <dc:attribute name="factory" value="wmsfloodplainfactory"/>
                        <dc:attribute name="ids" value="${river_id}"/>
                      </floodplain>
                    </dc:if>
                  </dc:elements>
                </dc:context>
              </dc:macro>
              <dc:macro name="flood-map-hwslines">
                <dc:context>
                  <dc:statement>
                    SELECT count(*) as km_exists, name as name
                    FROM hws_lines WHERE river_id = ${river_id} GROUP BY name
                  </dc:statement>
                   <dc:elements>
                    <dc:if test="$km_exists>0">
                      <line>
                        <dc:attribute name="factory" value="wmslinefactory"/>
                        <dc:attribute name="ids" value="${river_id};${name}"/>
                        <dc:attribute name="name" value="${name}"/>
                      </line>
                    </dc:if>
                  </dc:elements>
                </dc:context>
              </dc:macro>
              <dc:macro name="flood-map-buildings">
                <dc:context>
                  <dc:statement>
                    SELECT count(*) as km_exists, name as name
                    FROM buildings WHERE river_id = ${river_id} GROUP BY name
                  </dc:statement>
                   <dc:elements>
                    <dc:if test="$km_exists>0">
                      <building>
                        <dc:attribute name="factory" value="wmsbuildingsfactory"/>
                        <dc:attribute name="ids" value="${river_id};${name}"/>
                        <dc:attribute name="name" value="${name}"/>
                      </building>
                    </dc:if>
                  </dc:elements>
                </dc:context>
              </dc:macro>
              <dc:macro name="flood-map-fixpoints">
                <dc:context>
                  <dc:statement>
                    SELECT count(*) as km_exists, name as name
                    FROM fixpoints WHERE river_id = ${river_id} GROUP BY name
                  </dc:statement>
                   <dc:elements>
                    <dc:if test="$km_exists>0">
                      <fixpoint>
                        <dc:attribute name="factory" value="wmsfixpointsfactory"/>
                        <dc:attribute name="ids" value="${river_id};${name}"/>
                        <dc:attribute name="name"  value="${name}"/>
                      </fixpoint>
                    </dc:if>
                  </dc:elements>
                </dc:context>
              </dc:macro>
              <dc:macro name="flood-map-gaugelocations">
                <dc:context>
                  <dc:statement>
                    SELECT count(*) as km_exists, name as name
                    FROM gauge_location WHERE river_id = ${river_id} GROUP BY name
                  </dc:statement>
                   <dc:elements>
                    <dc:if test="$km_exists>0">
                      <gaugelocation>
                        <dc:attribute name="factory" value="wmsgaugelocationfactory"/>
                        <dc:attribute name="ids" value="${river_id};${name}"/>
                        <dc:attribute name="name"  value="${name}"/>
                      </gaugelocation>
                    </dc:if>
                  </dc:elements>
                </dc:context>
              </dc:macro>
              <dc:macro name="flood-map-uesk">
                <uesk>
                  <calculations>
                    <current>
                      <bfg>
                        <dc:context>
                          <dc:statement>
                              SELECT count(*) as uesg_exist, name as name
                              FROM floodmaps
                              WHERE river_id = ${river_id} AND kind = 111
                              GROUP BY name, kind
                          </dc:statement>
                          <dc:elements>
                            <dc:if test="$uesg_exist>0">
                              <floodmaps>
                                <dc:attribute name="factory" value="wmsfloodmapsfactory"/>
                                <dc:attribute name="ids" value="${river_id};${name}"/>
                                <dc:attribute name="name" value="${name}"/>
                              </floodmaps>
                            </dc:if>
                          </dc:elements>
                        </dc:context>
                      </bfg>
                      <land>
                        <dc:context>
                          <dc:statement>
                              SELECT count(*) as uesg_exist, name as name
                              FROM floodmaps
                              WHERE river_id = ${river_id} AND kind = 112
                              GROUP BY name, kind
                          </dc:statement>
                          <dc:elements>
                            <dc:if test="$uesg_exist>0">
                              <floodmaps>
                                <dc:attribute name="factory" value="wmsfloodmapsfactory"/>
                                <dc:attribute name="ids" value="${river_id};${name}"/>
                                <dc:attribute name="name" value="${name}"/>
                              </floodmaps>
                            </dc:if>
                          </dc:elements>
                        </dc:context>
                      </land>
                    </current>
                    <potentiel>
                      <bfg>
                        <dc:context>
                          <dc:statement>
                              SELECT count(*) as uesg_exist, name as name
                              FROM floodmaps
                              WHERE river_id = ${river_id} AND kind = 121
                              GROUP BY name, kind
                          </dc:statement>
                          <dc:elements>
                            <dc:if test="$uesg_exist>0">
                              <floodmaps>
                                <dc:attribute name="factory" value="wmsfloodmapsfactory"/>
                                <dc:attribute name="ids" value="${river_id};${name}"/>
                                <dc:attribute name="name" value="${name}"/>
                              </floodmaps>
                            </dc:if>
                          </dc:elements>
                        </dc:context>
                      </bfg>
                      <land>
                        <dc:context>
                          <dc:statement>
                              SELECT count(*) as uesg_exist, name as name
                              FROM floodmaps
                              WHERE river_id = ${river_id} AND kind = 122
                              GROUP BY name, kind
                          </dc:statement>
                          <dc:elements>
                            <dc:if test="$uesg_exist>0">
                              <floodmaps>
                                <dc:attribute name="factory" value="wmsfloodmapsfactory"/>
                                <dc:attribute name="ids" value="${river_id};${name}"/>
                                <dc:attribute name="name" value="${name}"/>
                              </floodmaps>
                            </dc:if>
                          </dc:elements>
                        </dc:context>
                      </land>
                    </potentiel>
                  </calculations>
                </uesk>
              </dc:macro>
              <dc:macro name="flood-map-complete">
                  <buildings>
                    <dc:call-macro name="flood-map-buildings"/>
                  </buildings>
                  <catchments>
                    <dc:call-macro name="flood-map-catchments"/>
                  </catchments>
                  <fixpoints>
                    <dc:call-macro name="flood-map-fixpoints"/>
                  </fixpoints>
                  <hydrboundaries>
                    <dc:call-macro name="flood-map-hydr-boundaries"/>
                    <dc:call-macro name="flood-map-floodplain"/>
                  </hydrboundaries>
                  <kilometrage>
                      <riveraxis>
                          <dc:attribute name="factory" value="riveraxis"/>
                          <dc:attribute name="ids" value="${river_id}"/>
                      </riveraxis>
                    <dc:call-macro name="flood-map-km"/>
                    <dc:call-macro name="flood-map-qps"/>
                  </kilometrage>
                  <hwslines>
                    <dc:call-macro name="flood-map-hwslines"/>
                  </hwslines>
                  <dc:call-macro name="flood-map-uesk"/>
                  <gaugelocations>
                    <dc:call-macro name="flood-map-gaugelocations"/>
                  </gaugelocations>
                  <rastermap>
                      <background>
                          <dc:attribute name="factory" value="wmsbackground"/>
                          <dc:attribute name="ids" value="${river_id}"/>
                      </background>
                  </rastermap>
              </dc:macro>
          </dc:if>
          <dc:if test="dc:contains($artifact-outs, 'minfo-heights')">
            <dc:call-macro name="minfo-heights"/>
            <dc:macro name="minfo-heights">
              <bedheights>
                <dc:call-macro name="bed-heights-single"/>
                <dc:call-macro name="bed-heights-epoch"/>
              </bedheights>
            </dc:macro>
          </dc:if>
          <dc:if test="dc:contains($artifact-outs, 'minfo-heights-epoch')">
            <bedheights>
              <dc:call-macro name="bed-heights-epoch"/>
            </bedheights>
          </dc:if>
          <dc:macro name="bed-heights-single">
            <single>
              <dc:context>
                <dc:statement>
                    SELECT id          AS bedh_id,
                           year        AS bedh_year,
                           description AS bedh_descr
                    FROM bed_height_single WHERE river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <height>
                    <dc:attribute name="factory" value="bedheight"/>
                    <dc:attribute name="ids" value="bedheight-single-${bedh_id}-${bedh_year}"/>
                    <dc:attribute name="description" value="${bedh_descr}"/>
                  </height>
                </dc:elements>
              </dc:context>
            </single>
          </dc:macro>
          <dc:macro name="bed-heights-epoch">
            <epoch>
              <dc:context>
                <dc:statement>
                  SELECT id               AS bedh_id,
                         time_interval_id AS bedh_interval_id,
                         description      AS bedh_descr
                  FROM bed_height_epoch WHERE river_id = ${river_id}
                </dc:statement>
                <dc:elements>
                  <height>
                    <dc:attribute name="factory" value="bedheight"/>
                    <dc:attribute name="ids" value="bedheight-epoch-${bedh_id}-${bedh_interval_id}"/>
                    <dc:attribute name="description" value="${bedh_descr}"/>
                  </height>
                </dc:elements>
              </dc:context>
            </epoch>
          </dc:macro>
        </river>
      </dc:elements>
    </dc:context>
  </dc:macro>

  <dc:choose>
    <dc:comment>
      User specific part
      ------------------
    </dc:comment>
    <dc:when test="dc:contains($parameters, 'user-id')">


    <old_calculations>
      <!--      <dc:macro name="load-user">-->
        <dc:call-macro name="user-range">
        <dc:context connection="user">
          <dc:comment>
            Get the user and collection-id.
          </dc:comment>
          <dc:statement>
            SELECT u.id AS user_id, c.id AS collection_id, c.name as collection_name
            FROM collections c JOIN users u ON c.user_id = u.id
            WHERE u.gid = CAST(${user-id} AS uuid)
            ORDER BY c.creation DESC
        </dc:statement>


        <dc:macro name="range-filter">
                 <dc:statement>
                   SELECT m.id AS a_id,
                          m.state AS a_state,
                          m.gid AS a_gid,
                          m.creation AS a_creation,
                          COALESCE(ld_mode, '')      AS ld_m,
                          COALESCE(ld_locations, '') AS ld_l,
                          COALESCE(ld_from, '')      AS ld_f,
                          COALESCE(ld_to, '')        AS ld_t
                   FROM   master_artifacts_range m
                   WHERE  m.collection_id = ${collection_id} AND m.gid &lt;&gt; CAST(${artifact-id} AS uuid)
                   AND EXISTS (
                       SELECT id FROM artifact_data ad WHERE ad.artifact_id = m.id AND k = 'river' AND v = ${river})
                 </dc:statement>
                 <dc:elements>
                   <dc:variable name="from" type="number" expr="dc:fromValue($ld_m, $ld_l, $ld_f)"/>
                   <dc:variable name="to" type="number" expr="dc:toValue($ld_m, $ld_l, $ld_t)"/>
                   <dc:if test="($from &gt;= $fromkm and $from &lt;= $tokm) or ($to &lt;= $tokm and $to &gt;= $fromkm) or ($from &lt;= $fromkm and $to &gt;= $tokm)">
                     <dc:macro-body/>
                   </dc:if>
                 </dc:elements>
               </dc:macro>
 
        <!-- OFFICIAL LINES -->
        <dc:if test="dc:contains($artifact-outs, 'longitudinal_section')">
          <dc:comment comment=".wst -------------------------------"/>
          <officiallines>
            <dc:elements>
                <dc:context>
                  <dc:statement>
                    SELECT m.id AS a_id,
                           m.state AS a_state,
                           m.gid AS a_gid,
                           m.creation AS a_creation,
                           ardg.v AS gaugy,
                           arv.v AS wqsingle
                    FROM   master_artifacts m,
                           artifact_data ardg,
                           artifact_data arv
                    WHERE  m.collection_id = ${collection_id}
                      AND m.gid = CAST(${artifact-id} AS uuid)
                      AND ardg.artifact_id = m.id
                      AND ardg.k = 'ld_gaugename'
                      AND arv.artifact_id = m.id
                      AND arv.k = 'wq_single'
                      AND EXISTS (
                        SELECT id
                        FROM artifact_data ad
                        WHERE ad.artifact_id = m.id
                          AND k = 'river'
                          AND v = ${river})
                  </dc:statement>
                  <dc:elements>
                      <dc:context connection="system">
                        <dc:statement>
                          SELECT ol.wst_id AS wstid, ol.wst_column_pos AS wstcolpos, ol.name AS olname, ol.value AS oval
                          FROM official_q_values ol
                          WHERE ol.value = CAST(${wqsingle} AS NUMERIC(10,2)) AND ol.gauge_name = ${gaugy}
                        </dc:statement>
                        <dc:elements>
                          <dc:element name="${olname}">
                            <dc:attribute name="name" value="${olname}"/>
                            <dc:attribute name="ids" value="additionals-wstv-${wstcolpos}-${wstid}"/>
                            <dc:attribute name="factory" value="staticwkms"/>
                          </dc:element>
                        </dc:elements>
                      </dc:context>
                  </dc:elements>
                </dc:context>
          </dc:elements>
          </officiallines>
        </dc:if>
        <!-- END OFFICIAL LINES -->

        <dc:comment>
          SHOW W-DIFFERENCES
        </dc:comment>

       <dc:macro name="differences">
          <differences>
            <dc:elements>
                <dc:context>
                  <dc:call-macro name="range-filter">
                      <dc:context>
                        <dc:statement>
                          SELECT a.gid as aid, f.id AS fid, f.name AS facet_name, f.num AS facet_num, f.description as facet_description
                          FROM outs as o, facets as f, artifacts as a
                          WHERE f.name = 'w_differences' and f.out_id = o.id and o.artifact_id = ${a_id} and a.id = ${a_id}
                        </dc:statement>
                        <dc:elements>
                          <dc:element name="${facet_name}">
                            <dc:attribute name="description" value="${facet_description}"/>
                            <dc:attribute name="factory"     value="winfo"/>
                            <dc:attribute name="artifact-id" value="${aid}"/>
                            <dc:attribute name="ids"         value="${aid}"/>
                            <dc:attribute name="out"         value="w_differences"/>
                          </dc:element>
                        </dc:elements>
                      </dc:context>
                    </dc:call-macro>
                </dc:context>
            </dc:elements>
          </differences>
        </dc:macro>

        <dc:comment>
          SHOW REFERENCE CURVE
        </dc:comment>


        <dc:macro name="reference-curves">
          <reference_curves>
            <dc:elements>
                <dc:context>
                  <dc:call-macro name="user-range">
                      <dc:context>
                        <dc:statement>
                          SELECT a.gid as aid, f.id AS fid, f.name AS facet_name, f.num AS facet_num, f.description as facet_description
                          FROM outs as o, facets as f, artifacts as a
                          WHERE f.name = 'reference_curve' and f.out_id = o.id and o.artifact_id = ${a_id} and a.id = ${a_id}
                        </dc:statement>
                        <dc:elements>
                          <dc:element name="${facet_name}">
                            <dc:attribute name="description" value="${facet_description}"/>
                            <dc:attribute name="factory"     value="winfo"/>
                            <dc:attribute name="artifact-id" value="${aid}"/>
                            <dc:attribute name="ids"         value="${aid}"/>
                            <dc:attribute name="out"         value="reference_curve"/>
                          </dc:element>
                        </dc:elements>
                      </dc:context>
                    </dc:call-macro>
                </dc:context>
            </dc:elements>
          </reference_curves>
        </dc:macro>

        <dc:comment>
          SHOW COMPUTED DISCHARGE CURVES
        </dc:comment>

        <dc:macro name="computed-discharge-curve">
          <computed_discharge_curves>
            <dc:elements>
                <dc:context>
                  <dc:call-macro name="range-filter">
                      <dc:context>
                        <dc:statement>
                          SELECT a.gid as aid, f.id AS fid, f.name AS facet_name, f.num AS facet_num, f.description as facet_description
                          FROM outs as o, facets as f, artifacts as a
                          WHERE f.name = 'computed_discharge_curve.q' and f.out_id = o.id and o.artifact_id = ${a_id} and a.id = ${a_id}
                        </dc:statement>
                        <dc:elements>
                          <dc:element name="${facet_name}">
                            <dc:attribute name="description" value="${facet_description}"/>
                            <dc:attribute name="factory"     value="winfo"/>
                            <dc:attribute name="artifact-id" value="${aid}"/>
                            <dc:attribute name="ids"         value="${aid}"/>
                            <dc:attribute name="out"         value="computed_discharge_curve"/>
                          </dc:element>
                        </dc:elements>
                      </dc:context>
                    </dc:call-macro>
                </dc:context>
            </dc:elements>
          </computed_discharge_curves>
        </dc:macro>

        <dc:comment>
          CROSS SECTION
        </dc:comment>


        <dc:macro name="waterlevels">
          <waterlevels>
            <dc:elements>
              <dc:context>
                <dc:call-macro name="range-filter">
                     <dc:context>
                       <dc:statement>
                         SELECT id AS out_id
                         FROM outs
                         WHERE artifact_id = ${a_id} AND name = 'cross_section'
                       </dc:statement>
                       <dc:elements>
                         <dc:context>
                           <dc:statement>
                             SELECT name AS facet_name, num as facet_num, description AS facet_description
                             FROM facets
                             WHERE out_id = ${out_id}
                             ORDER BY num ASC, name DESC
                           </dc:statement>
                           <longitudinal_section_columns>
                             <dc:attribute name="description" value="${river} ${a_creation}"/>
                             <dc:elements>
                               <dc:element name="${facet_name}">
                                 <dc:attribute name="description" value="${facet_description}"/>
                                 <dc:attribute name="ids" value="${facet_num}"/>
                                 <dc:attribute name="factory" value="winfo"/>
                                 <dc:attribute name="artifact-id" value="${a_gid}"/>
                                 <dc:attribute name="out" value="cross_section"/>
                               </dc:element>
                             </dc:elements>
                           </longitudinal_section_columns>
                         </dc:context>
                       </dc:elements>
                     </dc:context>
                   </dc:call-macro>
               </dc:context>
             </dc:elements>
          </waterlevels>
        </dc:macro>


        <dc:macro name="longitudinal">
          <waterlevels>
            <dc:elements>
              <dc:context>
                <dc:call-macro name="range-filter">
                  <dc:context>
                     <dc:statement>
                       SELECT id AS out_id
                       FROM outs
                       WHERE artifact_id = ${a_id} AND name = 'longitudinal_section'
                     </dc:statement>
                     <dc:elements>
                       <dc:context>
                         <dc:statement>
                           SELECT name AS facet_name, num as facet_num, description AS facet_description
                           FROM facets
                           WHERE out_id = ${out_id}
                           ORDER BY num ASC, name DESC
                         </dc:statement>
                         <longitudinal_section_columns>
                             <dc:attribute name="description" value="${river} ${a_creation}"/>
                             <dc:elements>
                               <dc:element name="${facet_name}">
                                 <dc:attribute name="description" value="${facet_description}"/>
                                 <dc:attribute name="ids" value="${facet_num}"/>
                                 <dc:attribute name="factory" value="winfo"/>
                                 <dc:attribute name="artifact-id" value="${a_gid}"/>
                                 <dc:attribute name="out" value="longitudinal_section"/>
                               </dc:element>
                             </dc:elements>
                         </longitudinal_section_columns>
                       </dc:context>
                     </dc:elements>
                   </dc:context>
                 </dc:call-macro>
               </dc:context>
             </dc:elements>
          </waterlevels>
        </dc:macro>


        <dc:macro name="longitudinal-section">
          <waterlevels>
            <dc:elements>
              <dc:context>
                <dc:call-macro name="range-filter">
                   <dc:context>
                   <dc:statement>
                     SELECT id AS out_id
                     FROM outs
                     WHERE artifact_id = ${a_id} AND name = 'fix_longitudinal_section_curve'
                   </dc:statement>
                   <dc:elements>
                     <dc:context>
                     <!-- average und deviation ls_0 . ls_1 ...-->
                       <dc:statement>
                         SELECT name AS facet_name, num as facet_num, description AS facet_description
                         FROM facets
                         WHERE out_id = ${out_id} AND ( name LIKE 'fix_deviation_ls%' OR name LIKE 'fix_sector_average_ls%' OR name LIKE 'fix_analysis_events_ls%' OR name LIKE 'fix_reference_events_ls%' )
                         ORDER BY num ASC, name DESC
                       </dc:statement>
                       <waterlevels>
                         <dc:attribute name="description" value="${river} ${a_creation} ${collection_name}"/>
                         <dc:elements>
                           <dc:element name="${facet_name}">
                             <dc:attribute name="description" value="${facet_description}"/>
                             <dc:attribute name="ids"         value="${facet_num}"/>
                             <dc:attribute name="factory"     value="fixanalysis"/>
                             <dc:attribute name="artifact-id" value="${a_gid}"/>
                             <dc:attribute name="out"         value="fix_longitudinal_section_curve"/>
                           </dc:element>
                         </dc:elements>
                       </waterlevels>
                     </dc:context>
                   </dc:elements>
                  </dc:context>
                </dc:call-macro>
                </dc:context>
             </dc:elements>
          </waterlevels>
        </dc:macro>

        <dc:macro name="delta-wt">
          <waterlevels>
            <dc:elements>
              <dc:context>
                <dc:call-macro name="range-filter">
                   <dc:context>
                   <dc:statement>
                     SELECT id AS out_id
                     FROM outs
                     WHERE artifact_id = ${a_id} AND name = 'fix_deltawt_curve'
                   </dc:statement>
                   <dc:elements>
                     <dc:context>
                       <dc:statement>
                         SELECT name AS facet_name, num as facet_num, description AS facet_description
                         FROM facets
                         WHERE out_id = ${out_id} and ( name LIKE 'fix_sector_average_dwt%' OR name LIKE 'fix_deviation_dwt%' OR name = 'fix_analysis_events_dwt' OR name = 'fix_reference_events_dwt' OR name = 'fix_analysis_periods_dwt' )
                         ORDER BY num ASC, name DESC
                       </dc:statement>
                       <waterlevels>
                         <dc:attribute name="description" value="${river} ${a_creation} ${collection_name}"/>
                         <dc:elements>
                           <dc:element name="${facet_name}">
                             <dc:attribute name="description" value="${facet_description}"/>
                             <dc:attribute name="ids"         value="${facet_num}"/>
                             <dc:attribute name="factory"     value="fixanalysis"/>
                             <dc:attribute name="artifact-id" value="${a_gid}"/>
                             <dc:attribute name="out"         value="fix_deltawt_curve"/>
                           </dc:element>
                         </dc:elements>
                       </waterlevels>
                     </dc:context>
                   </dc:elements>
                  </dc:context>
                </dc:call-macro>
                </dc:context>
             </dc:elements>
          </waterlevels>
        </dc:macro>


        <dc:macro name="fix-derivate-curve">
          <waterlevels>
            <dc:elements>
              <dc:context>
                <dc:call-macro name="range-filter">
                   <dc:context>
                   <dc:statement>
                     SELECT id AS out_id
                     FROM outs
                     WHERE artifact_id = ${a_id} AND name = 'fix_derivate_curve'
                   </dc:statement>
                   <dc:elements>
                     <dc:context>
                       <dc:statement>
                         SELECT name AS facet_name, num as facet_num, description AS facet_description
                         FROM facets
                         WHERE out_id = ${out_id} and name = 'fix_derivate_curve'
                         ORDER BY num ASC, name DESC
                       </dc:statement>
                       <waterlevels>
                         <dc:attribute name="description" value="${river} ${a_creation} ${collection_name}"/>
                         <dc:elements>
                           <dc:element name="${facet_name}">
                             <dc:attribute name="description" value="${facet_description}"/>
                             <dc:attribute name="ids"         value="${facet_num}"/>
                             <dc:attribute name="factory"     value="fixanalysis"/>
                             <dc:attribute name="artifact-id" value="${a_gid}"/>
                             <dc:attribute name="out"         value="fix_derivate_curve"/>
                           </dc:element>
                         </dc:elements>
                       </waterlevels>
                     </dc:context>
                   </dc:elements>
                  </dc:context>
                </dc:call-macro>
                </dc:context>
             </dc:elements>
          </waterlevels>
        </dc:macro>


        <dc:macro name="fix-wq-curve">
          <waterlevels>
            <dc:elements>
              <dc:context>
                <dc:call-macro name="range-filter">
                   <dc:context>
                   <dc:statement>
                     SELECT id AS out_id
                     FROM outs
                     WHERE artifact_id = ${a_id} AND name = 'fix_wq_curve'
                   </dc:statement>
                   <dc:elements>
                     <dc:context>
                       <dc:statement>
                         SELECT name AS facet_name, num as facet_num, description AS facet_description
                         FROM facets
                         WHERE out_id = ${out_id} and ( name LIKE 'fix_sector_average_wq%' OR name = 'fix_wq_curve' OR name LIKE 'fix_analysis_events_wq%' OR name LIKE 'fix_reference_events_wq%' )
                         ORDER BY num ASC, name DESC
                       </dc:statement>
                       <waterlevels>
                         <dc:attribute name="description" value="${river} ${a_creation} ${collection_name}"/>
                         <dc:elements>
                           <dc:element name="${facet_name}">
                             <dc:attribute name="description" value="${facet_description}"/>
                             <dc:attribute name="ids"         value="${facet_num}"/>
                             <dc:attribute name="factory"     value="fixanalysis"/>
                             <dc:attribute name="artifact-id" value="${a_gid}"/>
                             <dc:attribute name="out"         value="fix_wq_curve"/>
                           </dc:element>
                         </dc:elements>
                       </waterlevels>
                     </dc:context>
                   </dc:elements>
                  </dc:context>
                </dc:call-macro>
                </dc:context>
             </dc:elements>
          </waterlevels>
        </dc:macro>


        <dc:macro name="duration-curve">
          <computed_discharge_curves>
            <dc:elements>
                <dc:context>
                  <dc:call-macro name="range-filter">
                      <dc:context>
                        <dc:statement>
                          SELECT a.gid as aid, f.id AS fid, f.name AS facet_name, f.num AS facet_num, f.description as facet_description
                          FROM outs as o, facets as f, artifacts as a
                          WHERE (f.name = 'duration_curve.q' or f.name = 'duration_curve.w') and f.out_id = o.id and o.artifact_id = ${a_id} and a.id = ${a_id}
                        </dc:statement>
                        <dc:elements>
                          <dc:element name="${facet_name}">
                            <dc:attribute name="description" value="${facet_description}"/>
                            <dc:attribute name="factory"     value="winfo"/>
                            <dc:attribute name="artifact-id" value="${aid}"/>
                            <dc:attribute name="ids"         value="${aid}"/>
                            <dc:attribute name="out"         value="duration_curve"/>
                          </dc:element>
                        </dc:elements>
                      </dc:context>
                    </dc:call-macro>
                </dc:context>
            </dc:elements>
          </computed_discharge_curves>
        </dc:macro>

        <dc:comment>
           WATERLEVELS - ONLY SHOW Ws
        </dc:comment>

        <!-- TODO doesnt work nicely for fix/wq-diags. -->

        <dc:macro name="waterlevels-fix">
          <waterlevels>
            <dc:elements>
              <dc:context>
                <dc:call-macro name="range-filter">
                   <dc:context>
                   <dc:statement>
                     SELECT id AS out_id
                     FROM outs
                     WHERE artifact_id = ${a_id} AND name = 'longitudinal_section'
                   </dc:statement>
                   <dc:elements>
                     <dc:context>
                       <dc:statement>
                         SELECT name AS facet_name, num as facet_num, description AS facet_description
                         FROM facets
                         WHERE out_id = ${out_id} and name = 'longitudinal_section.w'
                         ORDER BY num ASC, name DESC
                       </dc:statement>
                       <waterlevels>
                         <dc:attribute name="description" value="${river} ${a_creation} ${collection_name}"/>
                         <dc:elements>
                           <dc:element name="${facet_name}">
                             <dc:attribute name="description" value="${facet_description}"/>
                             <dc:attribute name="ids"         value="${facet_num}"/>
                             <dc:attribute name="factory"     value="winfo"/>
                             <dc:attribute name="artifact-id" value="${a_gid}"/>
                             <dc:attribute name="out"         value="longitudinal_section"/>
                           </dc:element>
                         </dc:elements>
                       </waterlevels>
                     </dc:context>
                   </dc:elements>
                  </dc:context>
                </dc:call-macro>
                </dc:context>
             </dc:elements>
          </waterlevels>
        </dc:macro>

        <dc:comment>
          SHOW FLOODMAPS
        </dc:comment>


        <dc:macro name="flood-map">
          <floodmap>
            <dc:elements>
                <dc:context>
                  <dc:call-macro name="range-filter">
                      <dc:context>
                        <dc:statement>
                          SELECT a.gid as aid, f.id AS fid, f.name AS facet_name, f.num AS facet_num, f.description as facet_description
                          FROM outs as o, facets as f, artifacts as a
                          WHERE f.name = 'floodmap.wsplgen' and f.out_id = o.id and o.artifact_id = ${a_id} and a.id = ${a_id}
                        </dc:statement>
                        <dc:elements>
                          <dc:element name="${facet_name}">
                            <dc:attribute name="description" value="${facet_description}"/>
                            <dc:attribute name="factory"     value="winfo"/>
                            <dc:attribute name="artifact-id" value="${aid}"/>
                            <dc:attribute name="ids"         value="${aid}"/>
                            <dc:attribute name="out"         value="floodmap"/>
                          </dc:element>
                        </dc:elements>
                      </dc:context>
                  </dc:call-macro>
                </dc:context>
            </dc:elements>
          </floodmap>
        </dc:macro>

        <dc:comment>
          MINFO bedheight difference
        </dc:comment>

        <dc:macro name="bed-difference">
          <fix_longitudinal_section_curve>
            <dc:elements>
                <dc:context>
                  <dc:call-macro name="range-filter">
                      <dc:context>
                        <dc:statement>
                          SELECT a.gid as aid, f.id AS fid, f.name AS facet_name, f.num AS facet_num, f.description as facet_description
                          FROM outs as o, facets as f, artifacts as a
                          WHERE (f.name = 'fix_sector_average_ls_0' or f.name = 'fix_sector_average_ls_1' or f.name = 'fix_sector_average_ls_2'
                                 or f.name = 'fix_sector_average_ls_3' or f.name = 'fix_analysis_events_ls' or f.name = 'fix_reference_events_ls')
                                and f.out_id = o.id and o.artifact_id = ${a_id} and a.id = ${a_id}
                        </dc:statement>
                        <fix_longitudinal_section_curve>
                            <dc:attribute name="description" value="${river} ${a_creation} ${collection_name}"/>
                            <dc:elements>
                            <dc:element name="${facet_name}">
                                <dc:attribute name="description" value="${facet_description}"/>
                                <dc:attribute name="factory"     value="fixanalysis"/>
                                <dc:attribute name="artifact-id" value="${aid}"/>
                                <dc:attribute name="ids"         value="${facet_num}"/>
                                <dc:attribute name="out"         value="fix_longitudinal_section_curve"/>
                            </dc:element>
                            </dc:elements>
                        </fix_longitudinal_section_curve>
                        </dc:context>
                    </dc:call-macro>
                </dc:context>
            </dc:elements>
          </fix_longitudinal_section_curve>
        </dc:macro>

        <dc:comment>
          MINFO bedheight middle
        </dc:comment>

        <dc:macro name="bed-height">
          <fix_vollmer_wq_curve>
            <dc:elements>
                <dc:context>
                  <dc:call-macro name="range-filter">
                      <dc:context>
                        <dc:statement>
                          SELECT a.gid as aid, f.id AS fid, f.name AS facet_name, f.num AS facet_num, f.description as facet_description
                          FROM outs as o, facets as f, artifacts as a
                          WHERE (f.name = 'longitudinal_section.w' or f.name = 'heightmarks_points')
                                and f.out_id = o.id and o.artifact_id = ${a_id} and a.id = ${a_id}
                        </dc:statement>
                        <fix_vollmer_wq_curve>
                            <dc:attribute name="description" value="${river} ${a_creation} ${collection_name}"/>
                            <dc:elements>
                                <dc:element name="${facet_name}">
                                    <dc:attribute name="description" value="${facet_description}"/>
                                    <dc:attribute name="factory"     value="fixanalysis"/>
                                    <dc:attribute name="artifact-id" value="${aid}"/>
                                    <dc:attribute name="ids"         value="${facet_num}"/>
                                    <dc:attribute name="out"         value="longitudinal_section"/>
                                </dc:element>
                            </dc:elements>
                        </fix_vollmer_wq_curve>
                        </dc:context>
                    </dc:call-macro>
                </dc:context>
            </dc:elements>
          </fix_vollmer_wq_curve>
        </dc:macro>

        <dc:if test="dc:contains($artifact-outs, 'longitudinal_section') or (dc:contains($artifact-outs, 'discharge_longitudinal_section') or (dc:contains($artifact-outs, 'w_differences')))">
          <dc:call-macro name="longitudinal"/>
        </dc:if>
        <dc:if test="dc:contains($artifact-outs, 'fix_deltawt_curve')">
          <dc:call-macro name="delta-wt"/>
        </dc:if>
        <dc:if test="dc:contains($artifact-outs, 'longitudinal_section') or (dc:contains($artifact-outs, 'w_differences') or (dc:contains($artifact-outs, 'discharge_longitudinal_section')))">
          <dc:call-macro name="differences"/>
        </dc:if>
        <dc:if test="dc:contains($artifact-outs, 'reference_curve')">
          <dc:call-macro name="reference-curves"/>
        </dc:if>
        <dc:if test="dc:contains($artifact-outs, 'computed_discharge_curve')">
          <dc:call-macro name="computed-discharge-curve"/>
        </dc:if>
        <dc:if test="dc:contains($artifact-outs, 'cross_section')">
          <dc:call-macro name="waterlevels"/>
        </dc:if>
        <dc:if test="dc:contains($artifact-outs, 'fix_longitudinal_section_curve')">
          <dc:call-macro name="longitudinal-section"/>
        </dc:if>
        <dc:if test="dc:contains($artifact-outs, 'fix_derivate_curve')">
          <dc:call-macro name="fix-derivate-curve"/>
        </dc:if>
        <dc:if test="dc:contains($artifact-outs, 'fix_wq_curve')">
          <dc:call-macro name="fix-wq-curve"/>
        </dc:if>
        <dc:if test="dc:contains($artifact-outs, 'duration_curve')">
          <dc:call-macro name="duration-curve"/>
        </dc:if>
        <dc:if test="dc:contains($artifact-outs, 'waterlevels') or (dc:contains($artifact-outs, 'fix_wq_curve'))">
          <dc:call-macro name="waterlevels-fix"/>
        </dc:if>
        <dc:if test="dc:contains($artifact-outs, 'floodmap') or dc:contains($artifact-outs, 'map')">
          <dc:call-macro name="flood-map"/>
        </dc:if>
        <dc:if test="dc:contains($artifact-outs, 'bed_difference_year') or dc:contains($artifact-outs, 'bed_difference_height_year')">
          <dc:call-macro name="bed-difference"/>
        </dc:if>
        <dc:if test="dc:contains($artifact-outs, 'bedheight_middle')">
          <dc:call-macro name="bed-height"/>
        </dc:if>

      </dc:context>
  </dc:call-macro>

      </old_calculations>


      <dc:comment>
        Include System specific part when 'load-system' is in parameters.
        -----------------------------------------------------------------
      </dc:comment>
      <dc:choose>
        <dc:when test="dc:contains($parameters,'load-system')">
          <dc:call-macro name="load-system"/>
        </dc:when>
      </dc:choose>
    </dc:when>


    <dc:comment>
      Include System specific part only if no user ID is given.
      ---------------------------------------------------------
    </dc:comment>
    <dc:otherwise>
        <dc:call-macro name="load-system"/>
    </dc:otherwise>
  </dc:choose>
</datacage>
</dc:template>

http://dive4elements.wald.intevation.org