changeset 5523:35dba807966a

Applied contrib/inline-dc-attribute.xsl und fix idention. Need testing
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 29 Mar 2013 14:25:36 +0100
parents eeac800eb4cd
children 3badc699af0e
files flys-artifacts/doc/conf/meta-data.xml
diffstat 1 files changed, 1590 insertions(+), 1728 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/doc/conf/meta-data.xml	Fri Mar 29 11:07:24 2013 +0100
+++ b/flys-artifacts/doc/conf/meta-data.xml	Fri Mar 29 14:25:36 2013 +0100
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <dc:template xmlns:dc="http://www.intevation.org/2011/Datacage">
 <datacage>
   <dc:comment>
@@ -36,7 +36,7 @@
                  COALESCE(ld_from, '')      AS ldf,
                  COALESCE(ld_to, '')        AS ldt
           FROM master_artifacts_range
-          WHERE gid = CAST(${artifact-id} as uuid)
+          WHERE gid = CAST(${artifact-id} AS uuid)
         </dc:statement>
         <dc:for-each>
           <dc:variable name="fromkm" type="number" expr="dc:fromValue($ldm, $ldl, $ldf)"/>
@@ -59,7 +59,7 @@
   <dc:macro name="load-system">
     <dc:context connection="system">
       <dc:statement>
-        SELECT id AS river_id, name as river_name FROM rivers
+        SELECT id AS river_id, name AS river_name FROM rivers
         WHERE lower(name) LIKE lower(${river})
       </dc:statement>
       <dc:for-each>
@@ -78,17 +78,14 @@
                   FROM wsts WHERE kind = 0 AND river_id = ${river_id}
                 </dc:statement>
                 <dc:for-each>
-                  <basedata>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                  <basedata name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
                       <dc:for-each>
-                        <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>
+                        <column name="{$prot_column_name}"
+                                ids="base_data-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
                       </dc:for-each>
                     </dc:context>
                   </basedata>
@@ -109,17 +106,14 @@
                   FROM wsts WHERE kind = 0 AND river_id = ${river_id}
                 </dc:statement>
                 <dc:for-each>
-                  <basedata>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                  <basedata name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
                       <dc:for-each>
-                        <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>
+                        <column name="{$prot_column_name}"
+                                ids="base_data-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="wqinterpol"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
                       </dc:for-each>
                     </dc:context>
                   </basedata>
@@ -140,20 +134,16 @@
                   FROM wsts WHERE kind = 1 AND river_id = ${river_id}
                 </dc:statement>
                 <dc:for-each>
-                  <additional>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                  <additional name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
                       <dc:for-each>
-                        <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>
+                        <column name="{$prot_column_name}"
+                                ids="additionalsmarks-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
                       </dc:for-each>
-                    </dc:context>
-                  </additional>
+                    </dc:context></additional>
                 </dc:for-each>
               </dc:context>
             </additionals>
@@ -171,17 +161,14 @@
                   FROM wsts WHERE kind = 1 AND river_id = ${river_id}
                 </dc:statement>
                 <dc:for-each>
-                  <additional>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                  <additional name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
                       <dc:for-each>
-                        <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>
+                        <column name="{$prot_column_name}"
+                                ids="additionals-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
                       </dc:for-each>
                     </dc:context>
                   </additional>
@@ -202,17 +189,14 @@
                   FROM wsts WHERE kind = 1 AND river_id = ${river_id}
                 </dc:statement>
                 <dc:for-each>
-                  <relativepoint>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                  <relativepoint name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
                       <dc:for-each>
-                        <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>
+                        <column name="{$prot_column_name}"
+                                ids="additionals-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
                       </dc:for-each>
                     </dc:context>
                   </relativepoint>
@@ -232,18 +216,14 @@
                   FROM wsts WHERE kind = 2 AND river_id = ${river_id}
                 </dc:statement>
                 <dc:for-each>
-                  <fixation>
-                    <dc:attribute name="name" value="${prot_description}"/>
-                    <!--dc:attribute name="ids" value="fixations-wstv-A-${prot_id}"/-->
-                    <dc:context>
+                  <fixation name="{$prot_description}">
+                    <!--dc:attribute name="ids" value="fixations-wstv-A-${prot_id}"/--><dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
                       <dc:for-each>
-                        <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>
+                        <column name="{$prot_column_name}"
+                                ids="fixations-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="wqinterpol"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
                       </dc:for-each>
                     </dc:context>
                   </fixation>
@@ -263,17 +243,14 @@
                   FROM wsts WHERE kind = 2 AND river_id = ${river_id}
                 </dc:statement>
                 <dc:for-each>
-                  <fixation>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                  <fixation name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
                       <dc:for-each>
-                        <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>
+                        <column name="{$prot_column_name}"
+                                ids="fixations-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="wqinterpol"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
                       </dc:for-each>
                     </dc:context>
                   </fixation>
@@ -293,17 +270,14 @@
                   FROM wsts WHERE kind = 2 AND river_id = ${river_id}
                 </dc:statement>
                 <dc:for-each>
-                  <fixation>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                  <fixation name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
                       <dc:for-each>
-                        <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>
+                        <column name="{$prot_column_name}"
+                                ids="fixations-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
                       </dc:for-each>
                     </dc:context>
                   </fixation>
@@ -323,17 +297,14 @@
                   FROM wsts WHERE kind = 2 AND river_id = ${river_id}
                 </dc:statement>
                 <dc:for-each>
-                  <relativepoint>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                  <relativepoint name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
                       <dc:for-each>
-                        <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>
+                        <column name="{$prot_column_name}"
+                                ids="fixations-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
                       </dc:for-each>
                     </dc:context>
                   </relativepoint>
@@ -354,17 +325,14 @@
                   FROM wsts WHERE kind = 3 AND river_id = ${river_id}
                 </dc:statement>
                 <dc:for-each>
-                  <official>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                  <official name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
                       <dc:for-each>
-                        <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>
+                        <column name="{$prot_column_name}"
+                                ids="additionals-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwqkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
                       </dc:for-each>
                     </dc:context>
                   </official>
@@ -384,17 +352,14 @@
                   FROM wsts WHERE kind = 4 AND river_id = ${river_id}
                 </dc:statement>
                 <dc:for-each>
-                  <relativepoint>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                  <relativepoint name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
                       <dc:for-each>
-                        <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>
+                        <column name="{$prot_column_name}"
+                                ids="heightmarks_points-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
                       </dc:for-each>
                     </dc:context>
                   </relativepoint>
@@ -414,17 +379,14 @@
                   FROM wsts WHERE kind = 4 AND river_id = ${river_id}
                 </dc:statement>
                 <dc:for-each>
-                  <heightmark>
-                    <dc:attribute name="name" value="${prot_description}"/>
+                  <heightmark name="{$prot_description}">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
                       <dc:for-each>
-                        <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>
+                        <column name="{$prot_column_name}"
+                                ids="heightmarks_points-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
                       </dc:for-each>
                     </dc:context>
                   </heightmark>
@@ -444,17 +406,13 @@
                   FROM wsts WHERE kind = 4 AND river_id = ${river_id}
                 </dc:statement>
                 <dc:for-each>
-                  <heightmark>
-                    <dc:attribute name="name" value="${prot_description}"/>
-                    <dc:context>
+                  <heightmark name="{$prot_description}"><dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
                       <dc:for-each>
-                        <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>
+                        <column name="{$prot_column_name}"
+                                ids="heightmarks_annotations-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="wqinterpol"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
                       </dc:for-each>
                     </dc:context>
                   </heightmark>
@@ -466,8 +424,7 @@
 
         <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}"/>
+            <flood_protections id="flood-protections-{$river_id}">
               <dc:context connection="system">
                 <dc:statement>
                   SELECT id          AS prot_id,
@@ -475,34 +432,29 @@
                   FROM wsts WHERE kind = 5 AND river_id = ${river_id}
                 </dc:statement>
                 <dc:for-each>
-                  <relativepoint>
-                    <dc:attribute name="name" value="${prot_description}"/>
-                    <dc:attribute name="db-id" value="${prot_id}"/>
-                    <dc:attribute name="factory" value="staticwkms"/>
-                    <columns>
+                  <relativepoint name="{$prot_description}"
+                                 db-id="{$prot_id}"
+                                 factory="staticwkms">
+                  <columns>
                       <dc:context>
                         <dc:call-macro name="SQL-wst_columns_statement"/>
                         <dc:for-each>
-                          <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>
+                          <column name="{$prot_column_name}"
+                                  ids="flood_protection-wstv-{$prot_rel_pos}-{$prot_id}"
+                                  factory="staticwkms"
+                                  info="{$info} [km {$deffrom} - {$defto}]"/>
                         </dc:for-each>
                       </dc:context>
                     </columns>
                   </relativepoint>
                 </dc:for-each>
-              </dc:context>
-            </flood_protections>
+              </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}"/>
+            <flood_protections id="flood-protections-{$river_id}">
               <dc:context connection="system">
                 <dc:statement>
                   SELECT id          AS prot_id,
@@ -510,19 +462,16 @@
                   FROM wsts WHERE kind = 5 AND river_id = ${river_id}
                 </dc:statement>
                 <dc:for-each>
-                  <flood_protection>
-                    <dc:attribute name="name" value="${prot_description}"/>
-                    <dc:attribute name="db-id" value="${prot_id}"/>
-                    <dc:attribute name="factory" value="staticwkms"/>
+                  <flood_protection name="{$prot_description}"
+                                    db-id="{$prot_id}"
+                                    factory="staticwkms">
                     <dc:context>
                       <dc:call-macro name="SQL-wst_columns_statement"/>
                       <dc:for-each>
-                        <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>
+                        <column name="{$prot_column_name}"
+                                ids="flood_protection-wstv-{$prot_rel_pos}-{$prot_id}"
+                                factory="staticwkms"
+                                info="{$info} [km {$deffrom} - {$defto}]"/>
                       </dc:for-each>
                     </dc:context>
                   </flood_protection>
@@ -533,53 +482,32 @@
         </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>
+          <mainvalue factory="mainvalue" ids="{$river_id}"/>
+          <wmainvalue factory="mainvalue" ids="{$river_id}:w"/>
+          <qmainvalue factory="mainvalue" ids="{$river_id}:q"/>
         </dc:macro>
 
         <dc:macro name="qsectors">
-          <qsector>
-            <dc:attribute name="factory" value="qsectors"/>
-            <dc:attribute name="ids"     value="${river_id}"/>
-          </qsector>
+          <qsector factory="qsectors" ids="{$river_id}"/>
         </dc:macro>
 
         <dc:macro name="annotations">
-          <annotation>
-            <dc:attribute name="factory" value="annotations"/>
-            <dc:attribute name="ids"     value="${river_id}"/>
-          </annotation>
+          <annotation factory="annotations" ids="{$river_id}"/>
         </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>
+              <annotation name="all_annotations" factory="annotations" ids="{$river_id}"/>
               <dc:statement>
                 SELECT id          AS anno_id,
                        name AS anno_description
                 FROM annotation_types
               </dc:statement>
               <dc:for-each>
-                <annotation>
-                  <dc:attribute name="name"    value="${anno_description}"/>
-                  <dc:attribute name="factory" value="annotations"/>
-                  <dc:attribute name="ids"     value="${river_id}:${anno_description}"/>
-                </annotation>
+                <annotation name="{$anno_description}"
+                            factory="annotations"
+                            ids="{$river_id}:{$anno_description}"/>
              </dc:for-each>
             </dc:context>
           </annotations>
@@ -587,8 +515,7 @@
 
         <dc:macro name="cross_sections">
           <dc:call-macro name="user-range">
-            <cross_sections>
-              <dc:attribute name="id" value="flood-protections-${river_id}"/>
+            <cross_sections id="flood-protections-{$river_id}">
               <dc:context connection="system">
                 <dc:statement>
                   SELECT DISTINCT
@@ -600,11 +527,9 @@
                     AND csl.km BETWEEN ${fromkm} AND ${tokm}
                 </dc:statement>
                 <dc:for-each>
-                  <cross_section>
-                    <dc:attribute name="name" value="${prot_description}"/>
-                    <dc:attribute name="ids" value="${prot_id}"/>
-                    <dc:attribute name="factory" value="crosssections"/>
-                  </cross_section>
+                  <cross_section name="{$prot_description}"
+                                 ids="{$prot_id}"
+                                 factory="crosssections"/>
                 </dc:for-each>
               </dc:context>
             </cross_sections>
@@ -613,8 +538,7 @@
 
         <dc:macro name="hyks">
           <dc:call-macro name="user-range">
-            <hyks>
-              <dc:attribute name="id" value="hyk-${river_id}"/>
+            <hyks id="hyk-{$river_id}">
               <dc:context connection="system">
                 <dc:statement>
                   SELECT DISTINCT
@@ -626,51 +550,43 @@
                     AND he.km BETWEEN ${fromkm} AND ${tokm}
                 </dc:statement>
                 <dc:for-each>
-                  <hyk>
-                    <dc:attribute name="name" value="${hyk_description}"/>
-                    <dc:attribute name="ids" value="${hyk_id}"/>
-                    <dc:attribute name="factory" value="hyk"/>
-                  </hyk>
+                  <hyk name="{$hyk_description}" ids="{$hyk_id}" factory="hyk"/>
                 </dc:for-each>
-              </dc:context>
-            </hyks>
+              </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:context connection="system">
                 <dc:statement>
                   SELECT id          AS fvmid,
                          description AS fvmd
                   FROM flow_velocity_measurements WHERE river_id = ${river_id}
                 </dc:statement>
                 <dc:for-each>
-                  <flow_velocity_measurement>
-                    <dc:attribute name="name" value="${fvmd}"/>
-                    <dc:attribute name="ids" value="${fvmid}"/>
-                    <dc:attribute name="factory" value="flowvelocity"/>
+                  <flow_velocity_measurement name="{$fvmd}"
+                                             ids="{$fvmid}"
+                                             factory="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:for-each>
-                           <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:for-each>
+                      <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:for-each>
+                        <measurement_value name="{$id}-{$description}-{$station}-{$datetime}"
+                                           ids="{$id}"
+                                           factory="flowvelocity"/>
+                      </dc:for-each>
                     </dc:context>
                   </flow_velocity_measurement>
-              </dc:for-each>
-          </dc:context>
-          </flowvelocitymeasurement>
-        </dc:call-macro>
+                </dc:for-each>
+              </dc:context>
+            </flowvelocitymeasurement>
+          </dc:call-macro>
         </dc:macro>
 
         <dc:macro name="sounding-width">
@@ -683,11 +599,9 @@
                   FROM bed_height_single WHERE river_id = ${river_id}
               </dc:statement>
               <dc:for-each>
-                <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>
+                <height factory="bedheight"
+                        ids="bedheight-singlevalues-{$bedh_id}-{$bedh_year}"
+                        description="{$bedh_descr}"/>
               </dc:for-each>
             </dc:context>
           </soundings_width>
@@ -824,7 +738,6 @@
           </dc:otherwise>
         </dc:choose>
 
-
         <dc:if test="dc:contains($artifact-outs, 'waterlevels')">
 
           <!-- base data -->
@@ -843,28 +756,31 @@
           <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:comment><!-- XXX: Why is this taken out?
+          <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:comment>
 
         <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:for-each>
-                    <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>
+          <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:for-each>
+                  <gauge name="{$gauge_name}"
+                         db-id="{$gauge_id}"
+                         factory="gaugedischarge"
+                         from="{$g_start}"
+                         to="{$g_stop}"
+                         ids="{$gauge_name}"/>
+                  <dc:comment>
                     <!--
                     <gauge>
                       <dc:attribute name="name" value="${gauge_name}"/>
@@ -890,12 +806,12 @@
                         </dc:for-each>
                       </dc:context>
                     </gauge>
-                    -->
-                  </dc:for-each>
-                </dc:context>
-              </discharge_table_gauge>
-
-            </discharge_table_nn>
+                  -->
+                  </dc:comment>
+                </dc:for-each>
+              </dc:context>
+            </discharge_table_gauge>
+          </discharge_table_nn>
 
           <dc:call-macro name="basedata_2_fixations_wst"/>
 
@@ -914,729 +830,667 @@
         </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:for-each>
-                    <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:for-each>
-                </dc:context>
-              </discharge_table_gauge>
-            </discharge_table_nn>
+          <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:for-each>
+                  <gauge name="{$gauge_name}"
+                         db-id="{$gauge_id}"
+                         factory="gaugedischarge"
+                         from="{$g_start}"
+                         to="{$g_stop}"
+                         ids="{$gauge_name}"/>
+                </dc:for-each>
+              </dc:context>
+            </discharge_table_gauge>
+          </discharge_table_nn>
         </dc:if>
 
         <dc:if test="dc:contains($artifact-outs, 'floodmap') or dc:contains($artifact-outs, 'floodmap-hws')">
-            <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: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:if test="dc:contains($parameters, 'hws')">
-              <hws>
-                <dc:call-macro name="flood-map-hws-lines" />
-                <dc:call-macro name="flood-map-hws-points" />
-              </hws>
-            </dc:if>
+          </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_time || ' - ' || t.stop_time 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 d.river_id = ${river_id}
-                  </dc:statement>
-                  <dc:for-each>
-                      <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:for-each>
-                </dc:context>
-              </dems>
-            </dc:macro>
-            <dc:macro name="flood-map-hws-lines">
-              <dc:context>
-                <dc:statement>
-                  SELECT DISTINCT
-                         name AS hws_name,
-                         official AS hws_official,
-                         kind_id AS hws_kind
-                  FROM hws_lines
-                  WHERE river_id = ${river_id}
-                </dc:statement>
-                <lines>
-                  <official>
-                    <Durchlass>
-                      <dc:for-each filter="$hws_kind=1 and $hws_official=1">
-                          <hws>
-                            <dc:attribute name="factory" value="hwsfactory"/>
-                            <dc:attribute name="name" value="${hws_name}"/>
-                          </hws>
-                      </dc:for-each>
-                    </Durchlass>
-                    <Damm>
-                      <dc:for-each filter="$hws_kind=2 and $hws_official=1">
-                          <hws>
-                            <dc:attribute name="factory" value="hwsfactory"/>
-                            <dc:attribute name="name" value="${hws_name}"/>
-                          </hws>
-                      </dc:for-each>
-                    </Damm>
-                    <Graben>
-                      <dc:for-each filter="$hws_kind=3 and $hws_official=1">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_name}"/>
-                        </hws>
-                      </dc:for-each>
-                    </Graben>
-                  </official>
-                  <inofficial>
-                    <Durchlass>
-                      <dc:for-each filter="$hws_kind=1 and $hws_official=0">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_name}"/>
-                        </hws>
-                      </dc:for-each>
-                    </Durchlass>
-                    <Damm>
-                      <dc:for-each filter="$hws_kind=2 and $hws_official=0">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_name}"/>
-                        </hws>
-                      </dc:for-each>
-                    </Damm>
-                    <Graben>
-                      <dc:for-each filter="$hws_kind=3 and $hws_official=0">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_name}"/>
-                        </hws>
-                      </dc:for-each>
-                    </Graben>
-                  </inofficial>
-                </lines>
-              </dc:context>
-            </dc:macro>
-            <dc:macro name="flood-map-hws-points">
-              <dc:context>
-                <dc:statement>
-                  SELECT DISTINCT
-                         name AS hws_points_name,
-                         official AS hws_points_official,
-                         kind_id AS hws_points_kind
-                  FROM hws_points
-                  WHERE river_id = ${river_id}
-                </dc:statement>
-                <points>
-                  <official>
-                    <Durchlass>
-                      <dc:for-each filter="$hws_points_kind=1 and $hws_points_official=1">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_points_name}"/>
-                        </hws>
-                      </dc:for-each>
-                    </Durchlass>
-                    <Damm>
-                      <dc:for-each filter="$hws_points_kind=2 and $hws_points_official=1">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_points_name}"/>
-                        </hws>
-                      </dc:for-each>
-                    </Damm>
-                    <Graben>
-                      <dc:for-each filter="$hws_kind=3 and $hws_official=1">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_points_name}"/>
-                        </hws>
-                      </dc:for-each>
-                    </Graben>
-                  </official>
-                  <inofficial>
-                    <Durchlass>
-                      <dc:for-each filter="$hws_points_kind=1 and $hws_points_official=0">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_points_name}"/>
-                        </hws>
-                      </dc:for-each>
-                    </Durchlass>
-                    <Damm>
-                      <dc:for-each filter="$hws_points_kind=2 and $hws_points_official=0">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_points_name}"/>
-                        </hws>
-                      </dc:for-each>
-                    </Damm>
-                    <Graben>
-                      <dc:for-each filter="$hws_points_kind=3 and $hws_points_official=0">
-                        <hws>
-                          <dc:attribute name="factory" value="hwsfactory"/>
-                          <dc:attribute name="name" value="${hws_points_name}"/>
-                        </hws>
-                      </dc:for-each>
-                    </Graben>
-                  </inofficial>
-                </points>
-              </dc:context>
-            </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:for-each>
-                  <dc:if test="$km_exists>0">
-                    <kilometrage>
-                      <dc:attribute name="factory" value="wmskmfactory"/>
-                      <dc:attribute name="ids" value="${river_id}"/>
-                    </kilometrage>
-                  </dc:if>
-                </dc:for-each>
-              </dc:context>
-            </dc:macro>
-            <dc:macro name="flood-map-qps">
-              <dc:context>
-                <dc:comment>Grab only the actual first</dc:comment>
-                <dc:statement>
-                  SELECT DISTINCT
-                  cs.kind_id as kind_id,
-                  ck.name as kind_name
-                  FROM cross_section_tracks cs
-                  JOIN cross_section_track_kinds ck on cs.kind_id = ck.id
-                  WHERE river_id = ${river_id}
-                  AND kind_id=1
-                </dc:statement>
-                <dc:if test="dc:has-result()">
-                  <dc:for-each>
-                    <actual>
-                      <dc:attribute name="description" value="${kind_name}"/>
-                      <dc:attribute name="factory" value="wmsqpsfactory"/>
-                      <dc:attribute name="ids" value="${river_id};${kind_name};${kind_id}"/>
-                    </actual>
-                  </dc:for-each>
-                </dc:if>
-              </dc:context>
-              <dc:context>
-                <dc:comment>Now the other tracks</dc:comment>
-                <dc:statement>
-                  SELECT DISTINCT
-                  cs.kind_id as kind_id,
-                  ck.name as kind_name,
-                  cs.name as layer_name
-                  FROM cross_section_tracks cs
-                  JOIN cross_section_track_kinds ck on cs.kind_id = ck.id
-                  WHERE river_id = ${river_id}
-                  AND kind_id=0
-                </dc:statement>
-                <dc:if test="dc:has-result()">
-                  <other>
-                    <dc:for-each>
-                      <misc-qps>
-                        <dc:attribute name="description" value="${layer_name}"/>
-                        <dc:attribute name="factory" value="wmsqpsfactory"/>
-                        <dc:attribute name="ids" value="${river_id};${layer_name};${kind_id}"/>
-                      </misc-qps>
-                    </dc:for-each>
-                  </other>
-                </dc:if>
-              </dc:context>
-            </dc:macro>
-            <dc:macro name="flood-map-riveraxis">
-              <dc:context>
-                <dc:statement>
-                  SELECT DISTINCT
-                  ax.kind_id as kind_id,
-                  ak.name as kind_name
-                  FROM river_axes ax
-                  JOIN axis_kinds ak on ax.kind_id = ak.id
-                  WHERE river_id = ${river_id}
-                  AND kind_id=1
-                </dc:statement>
-                <dc:if test="dc:has-result()">
-                  <dc:for-each>
-                    <actual factory="riveraxis">
-                      <dc:attribute name="description" value="${kind_name}"/>
-                      <dc:attribute name="ids" value="${river_id};${kind_name};${kind_id}"/>
-                    </actual>
-                  </dc:for-each>
-                </dc:if>
-              </dc:context>
+          <dc:if test="dc:contains($parameters, 'hws')">
+            <hws>
+              <dc:call-macro name="flood-map-hws-lines"/>
+              <dc:call-macro name="flood-map-hws-points"/>
+            </hws>
+          </dc:if>
+
+          <dc:macro name="flood-map-recommended">
+            <dc:comment>
+               FIXME: Following two macros look identical to me.
+            </dc:comment>
+            <kilometrage>
+              <riveraxis factory="riveraxis" ids="{$river_id}"/>
+            </kilometrage>
+            <rastermap>
+              <background factory="wmsbackground" ids="{$river_id}"/>
+            </rastermap>
+          </dc:macro>
+
+          <dc:macro name="flood-map-dem">
+            <dems>
               <dc:context>
                 <dc:statement>
-                  SELECT DISTINCT
-                  ak.name as kind_name,
-                  ax.kind_id as kind_id,
-                  ax.name as layer_name
-                  FROM river_axes ax
-                  JOIN axis_kinds ak on ax.kind_id = ak.id
-                  WHERE river_id = ${river_id}
-                  AND kind_id &lt;&gt; 1
-                </dc:statement>
-                <dc:if test="dc:has-result()">
-                  <other>
-                    <dc:for-each>
-                      <misc-axis factory="riveraxis">
-                        <dc:attribute name="description" value="${layer_name}"/>
-                        <dc:attribute name="ids" value="${river_id};${layer_name};${kind_id}"/>
-                      </misc-axis>
-                    </dc:for-each>
-                  </other>
-                </dc:if>
-              </dc:context>
-            </dc:macro>
-            <dc:macro name="flood-map-hydr-boundaries-state">
-              <dc:context>
-                <dc:statement>
-                  SELECT DISTINCT
-                  name
-                  FROM hydr_boundaries
-                  WHERE river_id = ${river_id}
-                  AND kind = 2
+                  SELECT d.id    AS dem_id,
+                         r.a     AS dem_lower,
+                         r.b     AS dem_upper,
+                         d.name  AS name,
+                         d.projection || ' | ' || t.start_time || ' - ' || t.stop_time 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 d.river_id = ${river_id}
                 </dc:statement>
                 <dc:for-each>
-                  <line factory="wmshydrboundariesfactory"
-                    ids="{$river_id};{$name};2"
-                    name="{$name}"/>
-                </dc:for-each>
-              </dc:context>
-              <dc:context>
-                <dc:statement>
-                  SELECT DISTINCT
-                  name
-                  FROM hydr_boundaries_poly
-                  WHERE river_id = ${river_id}
-                  AND kind = 2
-                </dc:statement>
-                <dc:for-each>
-                  <line factory="wmshydrboundariespolyfactory"
-                    ids="{$river_id};{$name};2"
-                    name="{$name}"/>
+                    <dem factory="demfactory" ids="{$dem_id}" name="{$name}" info="{$info}"/>
                 </dc:for-each>
               </dc:context>
-            </dc:macro>
-            <dc:macro name="flood-map-hydr-boundaries-lines">
-              <dc:context>
-                <dc:statement>
-                  SELECT DISTINCT
-                  name
-                  FROM hydr_boundaries
-                  WHERE river_id = ${river_id}
-                  AND kind = 1
-                </dc:statement>
-                <dc:comment> What about all other line kinds?</dc:comment>
-                <dc:if test="dc:has-result()">
-                  <lines>
-                    <dc:for-each>
-                      <line factory="wmshydrboundariesfactory"
-                        ids="{$river_id};{$name};1"
-                        name="{$name}"/>
+            </dems>
+          </dc:macro>
+
+          <dc:macro name="flood-map-hws-lines">
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                       name AS hws_name,
+                       official AS hws_official,
+                       kind_id AS hws_kind
+                FROM hws_lines
+                WHERE river_id = ${river_id}
+              </dc:statement>
+              <lines>
+                <official>
+                  <Durchlass>
+                    <dc:for-each filter="$hws_kind=1 and $hws_official=1">
+                        <hws factory="hwsfactory" name="{$hws_name}"/>
                     </dc:for-each>
-                  </lines>
-                </dc:if>
-              </dc:context>
-            </dc:macro>
-            <dc:macro name="flood-map-hydr-boundaries-poly">
-              <dc:context>
-                <dc:statement>
-                  SELECT DISTINCT
-                  b.sectie AS sectie_id,
-                  sk.name AS sectie
-                  FROM hydr_boundaries_poly b
-                  JOIN sectie_kinds sk ON b.sectie = sk.id
-                  WHERE b.river_id = ${river_id}
-                  AND b.kind = 1
-                </dc:statement>
-                <dc:if test="dc:has-result()">
-                  <sobek_areas>
-                    <dc:for-each>
-                      <boundary name="{$sectie}"
-                        factory="wmshydrboundariespolyfactory"
-                        ids="{$river_id};{$sectie};1;{$sectie_id};-1"/>
+                  </Durchlass>
+                  <Damm>
+                    <dc:for-each filter="$hws_kind=2 and $hws_official=1">
+                        <hws factory="hwsfactory" name="{$hws_name}"/>
                     </dc:for-each>
-                  </sobek_areas>
+                  </Damm>
+                  <Graben>
+                    <dc:for-each filter="$hws_kind=3 and $hws_official=1">
+                      <hws factory="hwsfactory" name="{$hws_name}"/>
+                    </dc:for-each>
+                  </Graben>
+                </official>
+                <inofficial>
+                  <Durchlass>
+                    <dc:for-each filter="$hws_kind=1 and $hws_official=0">
+                      <hws factory="hwsfactory" name="{$hws_name}"/>
+                    </dc:for-each>
+                  </Durchlass>
+                  <Damm>
+                    <dc:for-each filter="$hws_kind=2 and $hws_official=0">
+                      <hws factory="hwsfactory" name="{$hws_name}"/>
+                    </dc:for-each>
+                  </Damm>
+                  <Graben>
+                    <dc:for-each filter="$hws_kind=3 and $hws_official=0">
+                      <hws factory="hwsfactory" name="{$hws_name}"/>
+                    </dc:for-each>
+                  </Graben>
+                </inofficial>
+              </lines>
+            </dc:context>
+          </dc:macro>
+
+          <dc:macro name="flood-map-hws-points">
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                       name AS hws_points_name,
+                       official AS hws_points_official,
+                       kind_id AS hws_points_kind
+                FROM hws_points
+                WHERE river_id = ${river_id}
+              </dc:statement>
+              <points>
+                <official>
+                  <Durchlass>
+                    <dc:for-each filter="$hws_points_kind=1 and $hws_points_official=1">
+                      <hws factory="hwsfactory" name="{$hws_points_name}"/>
+                    </dc:for-each>
+                  </Durchlass>
+                  <Damm>
+                    <dc:for-each filter="$hws_points_kind=2 and $hws_points_official=1">
+                      <hws factory="hwsfactory" name="{$hws_points_name}"/>
+                    </dc:for-each>
+                  </Damm>
+                  <Graben>
+                    <dc:for-each filter="$hws_kind=3 and $hws_official=1">
+                      <hws factory="hwsfactory" name="{$hws_points_name}"/>
+                    </dc:for-each>
+                  </Graben>
+                </official>
+                <inofficial>
+                  <Durchlass>
+                    <dc:for-each filter="$hws_points_kind=1 and $hws_points_official=0">
+                      <hws factory="hwsfactory" name="{$hws_points_name}"/>
+                    </dc:for-each>
+                  </Durchlass>
+                  <Damm>
+                    <dc:for-each filter="$hws_points_kind=2 and $hws_points_official=0">
+                      <hws factory="hwsfactory" name="{$hws_points_name}"/>
+                    </dc:for-each>
+                  </Damm>
+                  <Graben>
+                    <dc:for-each filter="$hws_points_kind=3 and $hws_points_official=0">
+                      <hws factory="hwsfactory" name="{$hws_points_name}"/>
+                    </dc:for-each>
+                  </Graben>
+                </inofficial>
+              </points>
+            </dc:context>
+          </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:for-each>
+                <dc:if test="$km_exists&gt;0">
+                  <kilometrage factory="wmskmfactory" ids="{$river_id}"/>
                 </dc:if>
-              </dc:context>
-              <dc:context>
-                <dc:statement>
-                  SELECT DISTINCT
-                  b.sobek AS sobek_id,
-                  sk.name AS sobek
-                  FROM hydr_boundaries_poly b
-                  JOIN sobek_kinds sk ON b.sobek = sk.id
-                  WHERE b.river_id = ${river_id}
-                  AND b.kind = 1
-                </dc:statement>
-                <dc:if test="dc:has-result()">
-                  <sobek_flooded>
-                    <dc:for-each>
-                      <boundary name="{$sobek}"
-                        factory="wmshydrboundariespolyfactory"
-                        ids="{$river_id};{$sobek};1;-1;{$sobek_id}"/>
-                    </dc:for-each>
-                  </sobek_flooded>
-                </dc:if>
-              </dc:context>
-            </dc:macro>
-            <dc:macro name="flood-map-hydr-boundaries">
-              <bfg_model>
-                <areas>
-                  <dc:call-macro name="flood-map-hydr-boundaries-poly"/>
-                </areas>
-                <dc:call-macro name="flood-map-hydr-boundaries-lines"/>
-              </bfg_model>
-              <federal>
-                <dc:call-macro name="flood-map-hydr-boundaries-state"/>
-              </federal>
-            </dc:macro>
-            <dc:macro name="flood-map-floodplain">
-              <dc:context>
-                <dc:statement>
-                  SELECT DISTINCT
-                  fp.kind_id as kind_id,
-                  flk.name as kind_name
-                  FROM floodplain fp
-                  JOIN floodplain_kinds flk on fp.kind_id = flk.id
-                  WHERE river_id = ${river_id}
-                  AND kind_id=1
-                </dc:statement>
-                <dc:if test="dc:has-result()">
+              </dc:for-each>
+            </dc:context>
+          </dc:macro>
+
+          <dc:macro name="flood-map-qps">
+            <dc:context>
+              <dc:comment>Grab only the actual first</dc:comment>
+              <dc:statement>
+                SELECT DISTINCT
+                cs.kind_id AS kind_id,
+                ck.name AS kind_name
+                FROM cross_section_tracks cs
+                JOIN cross_section_track_kinds ck on cs.kind_id = ck.id
+                WHERE river_id = ${river_id}
+                AND kind_id=1
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <dc:for-each>
+                  <actual description="{$kind_name}"
+                          factory="wmsqpsfactory"
+                          ids="{$river_id};{$kind_name};{$kind_id}"/>
+                </dc:for-each>
+              </dc:if>
+            </dc:context>
+            <dc:context>
+              <dc:comment>Now the other tracks</dc:comment>
+              <dc:statement>
+                SELECT DISTINCT
+                cs.kind_id AS kind_id,
+                ck.name AS kind_name,
+                cs.name AS layer_name
+                FROM cross_section_tracks cs
+                JOIN cross_section_track_kinds ck on cs.kind_id = ck.id
+                WHERE river_id = ${river_id}
+                AND kind_id=0
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <other>
+                  <dc:for-each>
+                    <misc-qps description="{$layer_name}"
+                              factory="wmsqpsfactory"
+                              ids="{$river_id};{$layer_name};{$kind_id}"/>
+                  </dc:for-each>
+                </other>
+              </dc:if>
+            </dc:context>
+          </dc:macro>
+
+          <dc:macro name="flood-map-riveraxis">
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                ax.kind_id AS kind_id,
+                ak.name AS kind_name
+                FROM river_axes ax
+                JOIN axis_kinds ak on ax.kind_id = ak.id
+                WHERE river_id = ${river_id}
+                AND kind_id=1
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <dc:for-each>
+                  <actual description="{$kind_name}"
+                          ids="{$river_id};{$kind_name};{$kind_id}"
+                          factory="riveraxis"/>
+                </dc:for-each>
+              </dc:if>
+            </dc:context>
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                ak.name AS kind_name,
+                ax.kind_id AS kind_id,
+                ax.name AS layer_name
+                FROM river_axes ax
+                JOIN axis_kinds ak on ax.kind_id = ak.id
+                WHERE river_id = ${river_id}
+                AND kind_id &lt;&gt; 1
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <other>
+                  <dc:for-each>
+                    <misc-axis description="{$layer_name}"
+                               ids="{$river_id};{$layer_name};{$kind_id}"
+                               factory="riveraxis"/>
+                  </dc:for-each>
+                </other>
+              </dc:if>
+            </dc:context>
+          </dc:macro>
+
+          <dc:macro name="flood-map-hydr-boundaries-state">
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                name
+                FROM hydr_boundaries
+                WHERE river_id = ${river_id}
+                AND kind = 2
+              </dc:statement>
+              <dc:for-each>
+                <line factory="wmshydrboundariesfactory" 
+                      ids="{$river_id};{$name};2"
+                      name="{$name}"/>
+              </dc:for-each>
+            </dc:context>
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                name
+                FROM hydr_boundaries_poly
+                WHERE river_id = ${river_id}
+                AND kind = 2
+              </dc:statement>
+              <dc:for-each>
+                <line factory="wmshydrboundariespolyfactory"
+                      ids="{$river_id};{$name};2"
+                      name="{$name}"/>
+              </dc:for-each>
+            </dc:context>
+          </dc:macro>
+
+          <dc:macro name="flood-map-hydr-boundaries-lines">
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                name
+                FROM hydr_boundaries
+                WHERE river_id = ${river_id}
+                AND kind = 1
+              </dc:statement>
+              <dc:comment> What about all other line kinds?</dc:comment>
+              <dc:if test="dc:has-result()">
+                <lines>
+                  <dc:for-each>
+                    <line factory="wmshydrboundariesfactory"
+                          ids="{$river_id};{$name};1"
+                          name="{$name}"/>
+                  </dc:for-each>
+                </lines>
+              </dc:if>
+            </dc:context>
+          </dc:macro>
+
+          <dc:macro name="flood-map-hydr-boundaries-poly">
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                b.sectie AS sectie_id,
+                sk.name AS sectie
+                FROM hydr_boundaries_poly b
+                JOIN sectie_kinds sk ON b.sectie = sk.id
+                WHERE b.river_id = ${river_id}
+                AND b.kind = 1
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <sobek_areas>
+                  <dc:for-each>
+                    <boundary name="{$sectie}"
+                              factory="wmshydrboundariespolyfactory"
+                              ids="{$river_id};{$sectie};1;{$sectie_id};-1"/>
+                  </dc:for-each>
+                </sobek_areas>
+              </dc:if>
+            </dc:context>
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                b.sobek AS sobek_id,
+                sk.name AS sobek
+                FROM hydr_boundaries_poly b
+                JOIN sobek_kinds sk ON b.sobek = sk.id
+                WHERE b.river_id = ${river_id}
+                AND b.kind = 1
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <sobek_flooded>
+                  <dc:for-each>
+                    <boundary name="{$sobek}"
+                              factory="wmshydrboundariespolyfactory"
+                              ids="{$river_id};{$sobek};1;-1;{$sobek_id}"/>
+                  </dc:for-each>
+                </sobek_flooded>
+              </dc:if>
+            </dc:context>
+          </dc:macro>
+
+          <dc:macro name="flood-map-hydr-boundaries">
+            <bfg_model>
+              <areas>
+                <dc:call-macro name="flood-map-hydr-boundaries-poly"/>
+              </areas>
+              <dc:call-macro name="flood-map-hydr-boundaries-lines"/>
+            </bfg_model>
+            <federal>
+              <dc:call-macro name="flood-map-hydr-boundaries-state"/>
+            </federal>
+          </dc:macro>
+
+          <dc:macro name="flood-map-floodplain">
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                fp.kind_id AS kind_id,
+                flk.name AS kind_name
+                FROM floodplain fp
+                JOIN floodplain_kinds flk on fp.kind_id = flk.id
+                WHERE river_id = ${river_id}
+                AND kind_id=1
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <dc:for-each>
+                  <floody factory="wmsfloodplainfactory"
+                          description="{$kind_name}"
+                          ids="{$river_id};{$kind_name};{$kind_id}"/>
+                </dc:for-each>
+              </dc:if>
+            </dc:context>
+            <dc:context>
+              <dc:statement>
+                SELECT DISTINCT
+                flk.name AS kind_name,
+                fp.kind_id AS kind_id,
+                fp.name AS layer_name
+                FROM floodplain fp
+                JOIN floodplain_kinds flk on fp.kind_id = flk.id
+                WHERE river_id = ${river_id}
+                AND kind_id &lt;&gt; 1
+              </dc:statement>
+              <dc:if test="dc:has-result()">
+                <other>
                   <dc:for-each>
                     <floody factory="wmsfloodplainfactory"
-                      description="{$kind_name}"
-                      ids="{$river_id};{$kind_name};{$kind_id}"/>
+                            description="{$layer_name}"
+                            ids="{$river_id};{$layer_name};{$kind_id}"/>
                   </dc:for-each>
-                </dc:if>
-              </dc:context>
-              <dc:context>
-                <dc:statement>
-                  SELECT DISTINCT
-                  flk.name as kind_name,
-                  fp.kind_id as kind_id,
-                  fp.name as layer_name
-                  FROM floodplain fp
-                  JOIN floodplain_kinds flk on fp.kind_id = flk.id
-                  WHERE river_id = ${river_id}
-                  AND kind_id &lt;&gt; 1
-                </dc:statement>
-                <dc:if test="dc:has-result()">
-                  <other>
-                    <dc:for-each>
-                      <floody factory="wmsfloodplainfactory"
-                        description="{$layer_name}"
-                        ids="{$river_id};{$layer_name};{$kind_id}"/>
-                    </dc:for-each>
-                  </other>
-                </dc:if>
-              </dc:context>
-            </dc:macro>
-
-            <dc:macro name="hwslines_by_kind">
-              <dc:comment>
-                Call from a context where fed_name hws_kind hws_name and river_id is
-                availble
-              </dc:comment>
-              <Durchlass>
-                <dc:for-each filter="$hws_kind=1">
-                  <hws>
-                    <dc:attribute name="factory" value="wmshwslinesfactory"/>
-                    <dc:attribute name="ids" value="${river_id};${hws_name}"/>
-                    <dc:attribute name="name" value="${hws_name}"/>
-                  </hws>
-                </dc:for-each>
-              </Durchlass>
-              <Damm>
-                <dc:for-each filter="$hws_kind=2">
-                  <hws>
-                    <dc:attribute name="factory" value="wmshwslinesfactory"/>
-                    <dc:attribute name="ids" value="${river_id};${hws_name}"/>
-                    <dc:attribute name="name" value="${hws_name}"/>
-                  </hws>
-                </dc:for-each>
-              </Damm>
-              <Graben>
-                <dc:for-each filter="$hws_kind=3">
-                  <hws>
-                    <dc:attribute name="factory" value="wmshwslinesfactory"/>
-                    <dc:attribute name="ids" value="${river_id};${hws_name}"/>
-                    <dc:attribute name="name" value="${hws_name}"/>
-                  </hws>
-                </dc:for-each>
-              </Graben>
-            </dc:macro>
+                </other>
+              </dc:if>
+            </dc:context>
+          </dc:macro>
 
-            <dc:macro name="hwslines">
-              <hws_lines>
-                <official>
-                  <dc:context>
-                    <dc:statement>
-                      SELECT DISTINCT
-                      fs.name AS fed_name,
-                      fs.id AS fed_id
-                      FROM hws_lines hws
-                      JOIN fed_states fs ON hws.fed_state_id = fs.id
-                      WHERE river_id = ${river_id}
-                      AND hws.official=1
-                    </dc:statement>
-                    <dc:for-each>
-                      <dc:context>
-                        <dc:statement>
-                          SELECT DISTINCT
-                          name AS hws_name,
-                          kind_id AS hws_kind
-                          FROM hws_lines
-                          WHERE river_id = ${river_id}
-                          AND official=1
-                          AND fed_state_id = ${fed_id} ORDER BY name
-                        </dc:statement>
-                        <fedstate>
-                          <dc:attribute name="description" value="${fed_name}"/>
-                          <dc:call-macro name="hwslines_by_kind"/>
-                        </fedstate>
-                      </dc:context>
-                    </dc:for-each>
-                  </dc:context>
-                  <dc:context>
-                    <dc:statement>
-                      SELECT distinct
-                      name AS hws_name,
-                      kind_id AS hws_kind
-                      FROM hws_lines
-                      WHERE river_id = ${river_id}
-                      AND official=1
-                      AND fed_state_id IS NULL
-                      ORDER BY name
-                    </dc:statement>
-                    <hws_fed_unknown>
-                      <dc:call-macro name="hwslines_by_kind"/>
-                    </hws_fed_unknown>
-                  </dc:context>
-                </official>
-                <inofficial>
-                  <dc:context>
-                    <dc:statement>
-                      SELECT DISTINCT
-                      fs.name AS fed_name,
-                      fs.id AS fed_id
-                      FROM hws_lines hws
-                      JOIN fed_states fs ON hws.fed_state_id = fs.id
-                      WHERE river_id = ${river_id}
-                      AND hws.official=0
-                    </dc:statement>
-                    <dc:for-each>
-                      <dc:context>
-                        <dc:statement>
-                          SELECT DISTINCT
-                          name AS hws_name,
-                          kind_id AS hws_kind
-                          FROM hws_lines
-                          WHERE river_id = ${river_id}
-                          AND official=0
-                          AND fed_state_id = ${fed_id} ORDER BY name
-                        </dc:statement>
-                        <fedstate>
-                          <dc:attribute name="description" value="${fed_name}"/>
-                          <dc:call-macro name="hwslines_by_kind"/>
-                        </fedstate>
-                      </dc:context>
-                    </dc:for-each>
-                  </dc:context>
-                  <dc:context>
-                    <dc:statement>
-                      SELECT distinct
-                      name AS hws_name,
-                      kind_id AS hws_kind
-                      FROM hws_lines
-                      WHERE river_id = ${river_id}
-                      AND official=0
-                      AND fed_state_id IS NULL ORDER BY name
-                    </dc:statement>
-                    <hws_fed_unknown>
-                      <dc:call-macro name="hwslines_by_kind"/>
-                    </hws_fed_unknown>
-                  </dc:context>
-                </inofficial>
+          <dc:macro name="hwslines_by_kind">
+            <dc:comment>
+              Call from a context where fed_name hws_kind hws_name and river_id is
+              availble
+            </dc:comment>
+            <Durchlass>
+              <dc:for-each filter="$hws_kind=1">
+                <hws factory="wmshwslinesfactory"
+                     ids="{$river_id};{$hws_name}"
+                     name="{$hws_name}"/>
+              </dc:for-each>
+            </Durchlass>
+            <Damm>
+              <dc:for-each filter="$hws_kind=2">
+                <hws factory="wmshwslinesfactory"
+                     ids="{$river_id};{$hws_name}"
+                     name="{$hws_name}"/>
+              </dc:for-each>
+            </Damm>
+            <Graben>
+              <dc:for-each filter="$hws_kind=3">
+                <hws factory="wmshwslinesfactory"
+                     ids="{$river_id};{$hws_name}"
+                     name="{$hws_name}"/>
+              </dc:for-each>
+            </Graben>
+          </dc:macro>
+
+          <dc:macro name="hwslines">
+            <hws_lines>
+              <official>
+                <dc:context>
+                  <dc:statement>
+                    SELECT DISTINCT
+                    fs.name AS fed_name,
+                    fs.id AS fed_id
+                    FROM hws_lines hws
+                    JOIN fed_states fs ON hws.fed_state_id = fs.id
+                    WHERE river_id = ${river_id}
+                    AND hws.official=1
+                  </dc:statement>
+                  <dc:for-each>
+                    <dc:context>
+                      <dc:statement>
+                        SELECT DISTINCT
+                        name AS hws_name,
+                        kind_id AS hws_kind
+                        FROM hws_lines
+                        WHERE river_id = ${river_id}
+                        AND official=1
+                        AND fed_state_id = ${fed_id} ORDER BY name
+                      </dc:statement>
+                      <fedstate description="{$fed_name}">
+                        <dc:call-macro name="hwslines_by_kind"/>
+                      </fedstate>
+                    </dc:context>
+                  </dc:for-each>
+                </dc:context>
+                <dc:context>
+                  <dc:statement>
+                    SELECT distinct
+                    name AS hws_name,
+                    kind_id AS hws_kind
+                    FROM hws_lines
+                    WHERE river_id = ${river_id}
+                    AND official=1
+                    AND fed_state_id IS NULL
+                    ORDER BY name
+                  </dc:statement>
+                  <hws_fed_unknown>
+                    <dc:call-macro name="hwslines_by_kind"/>
+                  </hws_fed_unknown>
+                </dc:context>
+              </official>
+              <inofficial>
+                <dc:context>
+                  <dc:statement>
+                    SELECT DISTINCT
+                    fs.name AS fed_name,
+                    fs.id AS fed_id
+                    FROM hws_lines hws
+                    JOIN fed_states fs ON hws.fed_state_id = fs.id
+                    WHERE river_id = ${river_id}
+                    AND hws.official=0
+                  </dc:statement>
+                  <dc:for-each>
+                    <dc:context>
+                      <dc:statement>
+                        SELECT DISTINCT
+                        name AS hws_name,
+                        kind_id AS hws_kind
+                        FROM hws_lines
+                        WHERE river_id = ${river_id}
+                        AND official=0
+                        AND fed_state_id = ${fed_id} ORDER BY name
+                      </dc:statement>
+                      <fedstate description="{$fed_name}">
+                        <dc:call-macro name="hwslines_by_kind"/>
+                      </fedstate>
+                    </dc:context>
+                  </dc:for-each>
+                </dc:context>
+                <dc:context>
+                  <dc:statement>
+                    SELECT distinct
+                    name AS hws_name,
+                    kind_id AS hws_kind
+                    FROM hws_lines
+                    WHERE river_id = ${river_id}
+                    AND official=0
+                    AND fed_state_id IS NULL ORDER BY name
+                  </dc:statement>
+                  <hws_fed_unknown>
+                    <dc:call-macro name="hwslines_by_kind"/>
+                  </hws_fed_unknown>
+                </dc:context>
+              </inofficial>
             </hws_lines>
           </dc:macro>
 
-            <dc:macro name="hwspoints_by_kind">
-              <dc:comment>
-                Call from a context where fed_name hws_kind hws_name and river_id is
-                availble
-              </dc:comment>
-              <Durchlass>
-                <dc:for-each filter="$hws_kind=1">
-                  <hws>
-                    <dc:attribute name="factory" value="wmshwspointsfactory"/>
-                    <dc:attribute name="ids" value="${river_id};${hws_name}"/>
-                    <dc:attribute name="name" value="${hws_name}"/>
-                  </hws>
-                </dc:for-each>
-              </Durchlass>
-              <Damm>
-                <dc:for-each filter="$hws_kind=2">
-                  <hws>
-                    <dc:attribute name="factory" value="wmshwspointsfactory"/>
-                    <dc:attribute name="ids" value="${river_id};${hws_name}"/>
-                    <dc:attribute name="name" value="${hws_name}"/>
-                  </hws>
-                </dc:for-each>
-              </Damm>
-              <Graben>
-                <dc:for-each filter="$hws_kind=3">
-                  <hws>
-                    <dc:attribute name="factory" value="wmshwspointsfactory"/>
-                    <dc:attribute name="ids" value="${river_id};${hws_name}"/>
-                    <dc:attribute name="name" value="${hws_name}"/>
-                  </hws>
-                </dc:for-each>
-              </Graben>
-            </dc:macro>
+          <dc:macro name="hwspoints_by_kind">
+            <dc:comment>
+              Call from a context where fed_name hws_kind hws_name and river_id is
+              availble
+            </dc:comment>
+            <Durchlass>
+              <dc:for-each filter="$hws_kind=1">
+                <hws factory="wmshwspointsfactory"
+                     ids="{$river_id};{$hws_name}"
+                     name="{$hws_name}"/>
+              </dc:for-each>
+            </Durchlass>
+            <Damm>
+              <dc:for-each filter="$hws_kind=2">
+                <hws factory="wmshwspointsfactory"
+                     ids="{$river_id};{$hws_name}"
+                     name="{$hws_name}"/>
+              </dc:for-each>
+            </Damm>
+            <Graben>
+              <dc:for-each filter="$hws_kind=3">
+                <hws factory="wmshwspointsfactory"
+                     ids="{$river_id};{$hws_name}"
+                     name="{$hws_name}"/>
+              </dc:for-each>
+            </Graben>
+          </dc:macro>
 
-            <dc:macro name="hwspoints">
-              <hws_points>
-                <official>
-                  <dc:context>
-                    <dc:statement>
-                      SELECT DISTINCT
-                      fs.name AS fed_name,
-                      fs.id AS fed_id
-                      FROM hws_points hws
-                      JOIN fed_states fs ON hws.fed_state_id = fs.id
-                      WHERE river_id = ${river_id}
-                      AND hws.official=1
-                    </dc:statement>
-                    <dc:for-each>
-                      <dc:context>
-                        <dc:statement>
-                          SELECT DISTINCT
-                          name AS hws_name,
-                          kind_id AS hws_kind
-                          FROM hws_points
-                          WHERE river_id = ${river_id}
-                          AND official=1
-                          AND fed_state_id = ${fed_id} ORDER BY name
-                        </dc:statement>
-                        <fedstate>
-                          <dc:attribute name="description" value="${fed_name}"/>
-                          <dc:call-macro name="hwspoints_by_kind"/>
-                        </fedstate>
-                      </dc:context>
-                    </dc:for-each>
-                  </dc:context>
-                  <dc:context>
-                    <dc:statement>
-                      SELECT distinct
-                      name AS hws_name,
-                      kind_id AS hws_kind
-                      FROM hws_points
-                      WHERE river_id = ${river_id}
-                      AND official=1
-                      AND fed_state_id IS NULL
-                      ORDER BY name
-                    </dc:statement>
-                    <hws_fed_unknown>
-                      <dc:call-macro name="hwspoints_by_kind"/>
-                    </hws_fed_unknown>
-                  </dc:context>
-                </official>
-                <inofficial>
-                  <dc:context>
-                    <dc:statement>
-                      SELECT DISTINCT
-                      fs.name AS fed_name,
-                      fs.id AS fed_id
-                      FROM hws_points hws
-                      JOIN fed_states fs ON hws.fed_state_id = fs.id
-                      WHERE river_id = ${river_id}
-                      AND hws.official=0
-                    </dc:statement>
-                    <dc:for-each>
-                      <dc:context>
-                        <dc:statement>
-                          SELECT DISTINCT
-                          name AS hws_name,
-                          kind_id AS hws_kind
-                          FROM hws_points
-                          WHERE river_id = ${river_id}
-                          AND official=0
-                          AND fed_state_id = ${fed_id} ORDER BY name
-                        </dc:statement>
-                        <fedstate>
-                          <dc:attribute name="description" value="${fed_name}"/>
-                          <dc:call-macro name="hwspoints_by_kind"/>
-                        </fedstate>
-                      </dc:context>
-                    </dc:for-each>
-                  </dc:context>
-                  <dc:context>
-                    <dc:statement>
-                      SELECT distinct
-                      name AS hws_name,
-                      kind_id AS hws_kind
-                      FROM hws_points
-                      WHERE river_id = ${river_id}
-                      AND official=0
-                      AND fed_state_id IS NULL ORDER BY name
-                    </dc:statement>
-                    <hws_fed_unknown>
-                      <dc:call-macro name="hwspoints_by_kind"/>
-                    </hws_fed_unknown>
-                  </dc:context>
-                </inofficial>
+          <dc:macro name="hwspoints">
+            <hws_points>
+              <official>
+                <dc:context>
+                  <dc:statement>
+                    SELECT DISTINCT
+                    fs.name AS fed_name,
+                    fs.id AS fed_id
+                    FROM hws_points hws
+                    JOIN fed_states fs ON hws.fed_state_id = fs.id
+                    WHERE river_id = ${river_id}
+                    AND hws.official=1
+                  </dc:statement>
+                  <dc:for-each>
+                    <dc:context>
+                      <dc:statement>
+                        SELECT DISTINCT
+                        name AS hws_name,
+                        kind_id AS hws_kind
+                        FROM hws_points
+                        WHERE river_id = ${river_id}
+                        AND official=1
+                        AND fed_state_id = ${fed_id} ORDER BY name
+                      </dc:statement>
+                      <fedstate description="{$fed_name}">
+                        <dc:call-macro name="hwspoints_by_kind"/>
+                      </fedstate>
+                    </dc:context>
+                  </dc:for-each>
+                </dc:context>
+                <dc:context>
+                  <dc:statement>
+                    SELECT distinct
+                    name AS hws_name,
+                    kind_id AS hws_kind
+                    FROM hws_points
+                    WHERE river_id = ${river_id}
+                    AND official=1
+                    AND fed_state_id IS NULL
+                    ORDER BY name
+                  </dc:statement>
+                  <hws_fed_unknown>
+                    <dc:call-macro name="hwspoints_by_kind"/>
+                  </hws_fed_unknown>
+                </dc:context>
+              </official>
+              <inofficial>
+                <dc:context>
+                  <dc:statement>
+                    SELECT DISTINCT
+                    fs.name AS fed_name,
+                    fs.id AS fed_id
+                    FROM hws_points hws
+                    JOIN fed_states fs ON hws.fed_state_id = fs.id
+                    WHERE river_id = ${river_id}
+                    AND hws.official=0
+                  </dc:statement>
+                  <dc:for-each>
+                    <dc:context>
+                      <dc:statement>
+                        SELECT DISTINCT
+                        name AS hws_name,
+                        kind_id AS hws_kind
+                        FROM hws_points
+                        WHERE river_id = ${river_id}
+                        AND official=0
+                        AND fed_state_id = ${fed_id} ORDER BY name
+                      </dc:statement>
+                      <fedstate description="{$fed_name}">
+                        <dc:call-macro name="hwspoints_by_kind"/>
+                      </fedstate>
+                    </dc:context>
+                  </dc:for-each>
+                </dc:context>
+                <dc:context>
+                  <dc:statement>
+                    SELECT distinct
+                    name AS hws_name,
+                    kind_id AS hws_kind
+                    FROM hws_points
+                    WHERE river_id = ${river_id}
+                    AND official=0
+                    AND fed_state_id IS NULL ORDER BY name
+                  </dc:statement>
+                  <hws_fed_unknown>
+                    <dc:call-macro name="hwspoints_by_kind"/>
+                  </hws_fed_unknown>
+                </dc:context>
+              </inofficial>
             </hws_points>
           </dc:macro>
 
@@ -1652,11 +1506,9 @@
                 AND b.kind_id &lt;&gt; 0
               </dc:statement>
               <dc:for-each>
-                <buildings>
-                  <dc:attribute name="description" value="${building_kind}"/>
-                  <dc:attribute name="factory" value="wmsbuildingsfactory"/>
-                  <dc:attribute name="ids" value="${river_id};${building_kind};${building_kind_id}"/>
-                </buildings>
+                <buildings description="{$building_kind}"
+                           factory="wmsbuildingsfactory"
+                           ids="{$river_id};{$building_kind};{$building_kind_id}"/>
               </dc:for-each>
             </dc:context>
             <dc:context>
@@ -1674,11 +1526,9 @@
               <dc:for-each>
                 <dc:element name="${building_kind}">
                   <dc:for-each>
-                    <buildings>
-                      <dc:attribute name="description" value="${building_name}"/>
-                      <dc:attribute name="factory" value="wmsbuildingsfactory"/>
-                      <dc:attribute name="ids" value="${river_id};${building_name}"/>
-                    </buildings>
+                    <buildings description="{$building_name}"
+                               factory="wmsbuildingsfactory"
+                               ids="{$river_id};{$building_name}"/>
                   </dc:for-each>
                 </dc:element>
               </dc:for-each>
@@ -1695,169 +1545,159 @@
               <dc:if test="dc:has-result()">
                 <jetties>
                   <dc:for-each>
-                    <jetty>
-                      <dc:attribute name="description" value="${jetty_kind}"/>
-                      <dc:attribute name="factory" value="wmsjettiesfactory"/>
-                      <dc:attribute name="ids" value="${river_id};${jetty_kind};${jetty_kind_id}"/>
-                    </jetty>
+                    <jetty description="{$jetty_kind}"
+                           factory="wmsjettiesfactory"
+                           ids="{$river_id};{$jetty_kind};{$jetty_kind_id}"/>
                   </dc:for-each>
                 </jetties>
               </dc:if>
             </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:for-each>
-                  <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:for-each>
-              </dc:context>
-            </dc:macro>
-            <dc:macro name="flood-map-gaugelocations">
-              <dc:attribute name="factory" value="externalwmsfactory"/>
-              <dc:attribute name="ids" value="http://www.pegelonline.wsv.de/webservices/gis/wms;Pegelpunkte;Pegelonline-Pegelpunkte"/>
-            </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:for-each>
-                          <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:for-each>
-                      </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:for-each>
-                          <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:for-each>
-                      </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:for-each>
-                          <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:for-each>
-                      </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:for-each>
-                          <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:for-each>
-                      </dc:context>
-                    </land>
-                  </potentiel>
-                </calculations>
-              </uesk>
-            </dc:macro>
 
-            <dc:macro name="flood-map-catchments">
-              <dc:attribute name="factory" value="externalwmsfactory"/>
-              <dc:attribute name="ids" value="http://geoportal.bafg.de/wmsproxy/INSPIRE/DrainageBasin;HY.PHYSICALWATERS.CATCHMENTS;Einzugsgebiet"/>
-            </dc:macro>
-
-            <dc:macro name="flood-map-routing">
-              <qps>
-                <dc:call-macro name="flood-map-qps"/>
-              </qps>
-              <dc:call-macro name="flood-map-fixpoints"/>
-              <dc:call-macro name="flood-map-km"/>
-              <axis>
-                <dc:call-macro name="flood-map-riveraxis"/>
-              </axis>
-            </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:for-each>
+                <dc:if test="$km_exists&gt;0">
+                  <fixpoint factory="wmsfixpointsfactory"
+                            ids="{$river_id};{$name}"
+                            name="{$name}"/>
+                </dc:if>
+              </dc:for-each>
+            </dc:context>
+          </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>
-                <!-- TODO: HW-Marken -->
-                <hws>
-                  <dc:call-macro name="hwslines"/>
-                  <dc:call-macro name="hwspoints"/>
-                </hws>
-                <route_data>
-                  <dc:call-macro name="flood-map-routing"/>
-                </route_data>
-                <hydrboundaries>
-                  <dc:call-macro name="flood-map-floodplain"/>
-                  <dc:call-macro name="flood-map-hydr-boundaries"/>
-                </hydrboundaries>
-                <dc:call-macro name="flood-map-uesk"/>
-                <gaugelocations>
-                  <dc:call-macro name="flood-map-gaugelocations"/>
-                </gaugelocations>
-                <background>
-                  <dc:attribute name="factory" value="wmsbackground"/>
-                  <dc:attribute name="ids" value="${river_id}"/>
-                </background>
-              </dc:macro>
+          <dc:macro name="flood-map-gaugelocations">
+            <dc:attribute name="factory" value="externalwmsfactory"/>
+            <dc:attribute name="ids" value="http://www.pegelonline.wsv.de/webservices/gis/wms;Pegelpunkte;Pegelonline-Pegelpunkte"/>
+          </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:for-each>
+                        <dc:if test="$uesg_exist&gt;0">
+                          <floodmaps factory="wmsfloodmapsfactory"
+                                     ids="{$river_id};{$name}"
+                                     name="{$name}"/>
+                        </dc:if>
+                      </dc:for-each>
+                    </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:for-each>
+                        <dc:if test="$uesg_exist&gt;0">
+                          <floodmaps factory="wmsfloodmapsfactory"
+                                     ids="{$river_id};{$name}"
+                                     name="{$name}"/>
+                        </dc:if>
+                      </dc:for-each>
+                    </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:for-each>
+                        <dc:if test="$uesg_exist&gt;0">
+                          <floodmaps factory="wmsfloodmapsfactory"
+                                     ids="{$river_id};{$name}"
+                                     name="{$name}"/>
+                        </dc:if>
+                      </dc:for-each>
+                    </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:for-each>
+                        <dc:if test="$uesg_exist&gt;0">
+                          <floodmaps factory="wmsfloodmapsfactory"
+                                     ids="{$river_id};{$name}"
+                                     name="{$name}"/>
+                        </dc:if>
+                      </dc:for-each>
+                    </dc:context>
+                  </land>
+                </potentiel>
+              </calculations>
+            </uesk>
+          </dc:macro>
+
+          <dc:macro name="flood-map-catchments">
+            <dc:attribute name="factory" value="externalwmsfactory"/>
+            <dc:attribute name="ids" value="http://geoportal.bafg.de/wmsproxy/INSPIRE/DrainageBasin;HY.PHYSICALWATERS.CATCHMENTS;Einzugsgebiet"/>
+          </dc:macro>
+
+          <dc:macro name="flood-map-routing">
+            <qps>
+              <dc:call-macro name="flood-map-qps"/>
+            </qps>
+            <dc:call-macro name="flood-map-fixpoints"/>
+            <dc:call-macro name="flood-map-km"/>
+            <axis>
+              <dc:call-macro name="flood-map-riveraxis"/>
+            </axis>
+          </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>
+            <dc:comment><!-- TODO: HW-Marken --></dc:comment>
+            <hws>
+              <dc:call-macro name="hwslines"/>
+              <dc:call-macro name="hwspoints"/>
+            </hws>
+            <route_data>
+              <dc:call-macro name="flood-map-routing"/>
+            </route_data>
+            <hydrboundaries>
+              <dc:call-macro name="flood-map-floodplain"/>
+              <dc:call-macro name="flood-map-hydr-boundaries"/>
+            </hydrboundaries>
+            <dc:call-macro name="flood-map-uesk"/>
+            <gaugelocations>
+              <dc:call-macro name="flood-map-gaugelocations"/>
+            </gaugelocations>
+            <background factory="wmsbackground" ids="{$river_id}"/>
+          </dc:macro>
+
         </dc:if>
+
         <dc:if test="dc:contains($artifact-outs, 'minfo-heights')">
           <dc:call-macro name="minfo-heights"/>
           <dc:macro name="minfo-heights">
@@ -1872,25 +1712,25 @@
             <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}
+                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:for-each>
-                <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>
+                <height factory="bedheight"
+                        ids="bedheight-single-{$bedh_id}-{$bedh_year}"
+                        description="{$bedh_descr}"/>
               </dc:for-each>
             </dc:context>
           </single>
         </dc:macro>
+
         <dc:macro name="bed-heights-epoch">
           <epoch>
             <dc:context>
@@ -1901,15 +1741,14 @@
                 FROM bed_height_epoch WHERE river_id = ${river_id}
               </dc:statement>
               <dc:for-each>
-                <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>
+                <height factory="bedheight"
+                        ids="bedheight-epoch-{$bedh_id}-{$bedh_interval_id}"
+                        description="{$bedh_descr}"/>
               </dc:for-each>
             </dc:context>
           </epoch>
         </dc:macro>
+
       </dc:for-each>
     </dc:context>
   </dc:macro>
@@ -1921,76 +1760,73 @@
     </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>
-
+      <old_calculations>
 
-        <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:for-each>
-                   <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:for-each>
-               </dc:macro>
- 
-        <!-- OFFICIAL LINES -->
-        <dc:if test="dc:contains($artifact-outs, 'longitudinal_section')">
-          <dc:comment comment=".wst -------------------------------"/>
-          <officiallines>
-            <dc:for-each>
-                <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:for-each>
+        <dc:comment><!-- <dc:macro name="load-user">--></dc:comment>
+        <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:for-each>
+                <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:for-each>
+            </dc:macro>
+     
+            <!-- OFFICIAL LINES -->
+            <dc:if test="dc:contains($artifact-outs, 'longitudinal_section')">
+              <dc:comment comment=".wst -------------------------------"/>
+              <officiallines>
+                <dc:for-each>
+                  <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:for-each>
                       <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
@@ -2005,634 +1841,660 @@
                           </dc:element>
                         </dc:for-each>
                       </dc:context>
-                  </dc:for-each>
-                </dc:context>
-          </dc:for-each>
-          </officiallines>
-        </dc:if>
-        <!-- END OFFICIAL LINES -->
+                    </dc:for-each>
+                  </dc:context>
+                </dc:for-each>
+              </officiallines>
+            </dc:if>
+            <!-- END OFFICIAL LINES -->
 
-        <dc:comment>
-          SHOW W-DIFFERENCES
-        </dc:comment>
+            <dc:comment>
+              SHOW W-DIFFERENCES
+            </dc:comment>
 
-       <dc:macro name="differences">
-          <differences>
-            <dc:for-each>
-                <dc:context>
-                  <dc:call-macro name="range-filter">
+            <dc:macro name="differences">
+              <differences>
+                <dc:for-each>
+                  <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
+                          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:for-each>
                           <dc:element name="${facet_name}">
                             <dc:attribute name="description" value="${facet_description}"/>
-                            <dc:attribute name="factory"     value="winfo"/>
+                            <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:attribute name="ids" value="${aid}"/>
+                            <dc:attribute name="out" value="w_differences"/>
                           </dc:element>
                         </dc:for-each>
                       </dc:context>
                     </dc:call-macro>
-                </dc:context>
-            </dc:for-each>
-          </differences>
-        </dc:macro>
+                  </dc:context>
+                </dc:for-each>
+              </differences>
+            </dc:macro>
 
-        <dc:comment>
-          SHOW REFERENCE CURVE
-        </dc:comment>
-
+            <dc:comment>
+              SHOW REFERENCE CURVE
+            </dc:comment>
 
-        <dc:macro name="reference-curves">
-          <reference_curves>
-            <dc:for-each>
-                <dc:context>
-                  <dc:call-macro name="user-range">
+            <dc:macro name="reference-curves">
+              <reference_curves>
+                <dc:for-each>
+                  <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
+                          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:for-each>
                           <dc:element name="${facet_name}">
                             <dc:attribute name="description" value="${facet_description}"/>
-                            <dc:attribute name="factory"     value="winfo"/>
+                            <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:attribute name="ids" value="${aid}"/>
+                            <dc:attribute name="out" value="reference_curve"/>
                           </dc:element>
                         </dc:for-each>
                       </dc:context>
-                    </dc:call-macro>
-                </dc:context>
-            </dc:for-each>
-          </reference_curves>
-        </dc:macro>
+                     </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </reference_curves>
+            </dc:macro>
 
-        <dc:comment>
-          SHOW COMPUTED DISCHARGE CURVES
-        </dc:comment>
+            <dc:comment>
+              SHOW COMPUTED DISCHARGE CURVES
+            </dc:comment>
 
-        <dc:macro name="computed-discharge-curve">
-          <computed_discharge_curves>
-            <dc:for-each>
-                <dc:context>
-                  <dc:call-macro name="range-filter">
+            <dc:macro name="computed-discharge-curve">
+              <computed_discharge_curves>
+                <dc:for-each>
+                  <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
+                          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:for-each>
                           <dc:element name="${facet_name}">
                             <dc:attribute name="description" value="${facet_description}"/>
-                            <dc:attribute name="factory"     value="winfo"/>
+                            <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:attribute name="ids" value="${aid}"/>
+                            <dc:attribute name="out" value="computed_discharge_curve"/>
                           </dc:element>
                         </dc:for-each>
                       </dc:context>
                     </dc:call-macro>
-                </dc:context>
-            </dc:for-each>
-          </computed_discharge_curves>
-        </dc:macro>
-
-        <dc:comment>
-          CROSS SECTION
-        </dc:comment>
-
-
-        <dc:macro name="waterlevels">
-          <waterlevels>
-            <dc:for-each>
-              <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:for-each>
-                         <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:for-each>
-                               <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:for-each>
-                           </longitudinal_section_columns>
-                         </dc:context>
-                       </dc:for-each>
-                     </dc:context>
-                   </dc:call-macro>
-               </dc:context>
-             </dc:for-each>
-          </waterlevels>
-        </dc:macro>
-
-
-        <dc:macro name="longitudinal">
-          <waterlevels>
-            <dc:for-each>
-              <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:for-each>
-                       <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:for-each>
-                               <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:for-each>
-                         </longitudinal_section_columns>
-                       </dc:context>
-                     </dc:for-each>
-                   </dc:context>
-                 </dc:call-macro>
-               </dc:context>
-             </dc:for-each>
-          </waterlevels>
-        </dc:macro>
-
-
-        <dc:macro name="longitudinal-section">
-          <waterlevels>
-            <dc:for-each>
-              <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:for-each>
-                     <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:for-each>
-                           <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:for-each>
-                       </waterlevels>
-                     </dc:context>
-                   </dc:for-each>
                   </dc:context>
-                </dc:call-macro>
-                </dc:context>
-             </dc:for-each>
-          </waterlevels>
-        </dc:macro>
-
-        <dc:macro name="delta-wt">
-          <waterlevels>
-            <dc:for-each>
-              <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:for-each>
-                     <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:for-each>
-                           <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:for-each>
-                       </waterlevels>
-                     </dc:context>
-                   </dc:for-each>
-                  </dc:context>
-                </dc:call-macro>
-                </dc:context>
-             </dc:for-each>
-          </waterlevels>
-        </dc:macro>
-
+                </dc:for-each>
+              </computed_discharge_curves>
+            </dc:macro>
 
-        <dc:macro name="fix-derivate-curve">
-          <waterlevels>
-            <dc:for-each>
-              <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:for-each>
-                     <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:for-each>
-                           <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:for-each>
-                       </waterlevels>
-                     </dc:context>
-                   </dc:for-each>
-                  </dc:context>
-                </dc:call-macro>
-                </dc:context>
-             </dc:for-each>
-          </waterlevels>
-        </dc:macro>
-
+            <dc:comment>
+              CROSS SECTION
+            </dc:comment>
 
-        <dc:macro name="fix-wq-curve">
-          <waterlevels>
-            <dc:for-each>
-              <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:for-each>
-                     <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:for-each>
-                           <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:for-each>
-                       </waterlevels>
-                     </dc:context>
-                   </dc:for-each>
-                  </dc:context>
-                </dc:call-macro>
-                </dc:context>
-             </dc:for-each>
-          </waterlevels>
-        </dc:macro>
-
-
-        <dc:macro name="duration-curve">
-          <computed_discharge_curves>
-            <dc:for-each>
-                <dc:context>
-                  <dc:call-macro name="range-filter">
+            <dc:macro name="waterlevels">
+              <waterlevels>
+                <dc:for-each>
+                  <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}
+                          SELECT id AS out_id
+                          FROM outs
+                          WHERE artifact_id = ${a_id} AND name = 'cross_section'
+                        </dc:statement>
+                        <dc:for-each>
+                          <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 description="{$river} {$a_creation}">
+                              <dc:for-each>
+                                <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:for-each>
+                            </longitudinal_section_columns>
+                          </dc:context>
+                        </dc:for-each>
+                      </dc:context>
+                    </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </waterlevels>
+            </dc:macro>
+
+            <dc:macro name="longitudinal">
+              <waterlevels>
+                <dc:for-each>
+                  <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:for-each>
+                          <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 description="{$river} {$a_creation}">
+                              <dc:for-each>
+                                <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:for-each>
+                            </longitudinal_section_columns>
+                          </dc:context>
+                        </dc:for-each>
+                      </dc:context>
+                    </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </waterlevels>
+            </dc:macro>
+
+            <dc:macro name="longitudinal-section">
+              <waterlevels>
+                <dc:for-each>
+                  <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:for-each>
+                          <dc:context>
+                            <dc:comment><!-- average und deviation ls_0 . ls_1 ...--></dc:comment>
+                            <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 description="{$river} {$a_creation} {$collection_name}">
+                              <dc:for-each>
+                                <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:for-each>
+                            </waterlevels>
+                          </dc:context>
+                        </dc:for-each>
+                      </dc:context>
+                    </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </waterlevels>
+            </dc:macro>
+
+            <dc:macro name="delta-wt">
+              <waterlevels>
+                <dc:for-each>
+                  <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:for-each>
+                          <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 description="{$river} {$a_creation} {$collection_name}">
+                              <dc:for-each>
+                                <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:for-each>
+                            </waterlevels>
+                          </dc:context>
+                        </dc:for-each>
+                      </dc:context>
+                    </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </waterlevels>
+            </dc:macro>
+
+            <dc:macro name="fix-derivate-curve">
+              <waterlevels>
+                <dc:for-each>
+                  <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:for-each>
+                          <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 description="{$river} {$a_creation} {$collection_name}">
+                              <dc:for-each>
+                                <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:for-each>
+                            </waterlevels>
+                          </dc:context>
+                        </dc:for-each>
+                      </dc:context>
+                    </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </waterlevels>
+            </dc:macro>
+
+            <dc:macro name="fix-wq-curve">
+              <waterlevels>
+                <dc:for-each>
+                  <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:for-each>
+                          <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 description="{$river} {$a_creation} {$collection_name}">
+                              <dc:for-each>
+                                <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:for-each>
+                            </waterlevels>
+                          </dc:context>
+                        </dc:for-each>
+                      </dc:context>
+                    </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </waterlevels>
+            </dc:macro>
+
+            <dc:macro name="duration-curve">
+              <computed_discharge_curves>
+                <dc:for-each>
+                  <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:for-each>
                           <dc:element name="${facet_name}">
                             <dc:attribute name="description" value="${facet_description}"/>
-                            <dc:attribute name="factory"     value="winfo"/>
+                            <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:attribute name="ids" value="${aid}"/>
+                            <dc:attribute name="out" value="duration_curve"/>
                           </dc:element>
                         </dc:for-each>
                       </dc:context>
                     </dc:call-macro>
-                </dc:context>
-            </dc:for-each>
-          </computed_discharge_curves>
-        </dc:macro>
-
-        <dc:comment>
-           WATERLEVELS - ONLY SHOW Ws
-        </dc:comment>
-
-        <!-- TODO doesnt work nicely for fix/wq-diags. -->
+                  </dc:context>
+                </dc:for-each>
+              </computed_discharge_curves>
+            </dc:macro>
 
-        <dc:macro name="waterlevels-fix">
-          <waterlevels>
-            <dc:for-each>
-              <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:for-each>
-                     <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:for-each>
-                           <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:for-each>
-                       </waterlevels>
-                     </dc:context>
-                   </dc:for-each>
-                  </dc:context>
-                </dc:call-macro>
-                </dc:context>
-             </dc:for-each>
-          </waterlevels>
-        </dc:macro>
+            <dc:comment>
+               WATERLEVELS - ONLY SHOW Ws
+            </dc:comment>
 
-        <dc:comment>
-          SHOW FLOODMAPS
-        </dc:comment>
-
+            <dc:comment><!-- TODO doesnt work nicely for fix/wq-diags. --></dc:comment>
 
-        <dc:macro name="flood-map">
-          <floodmap>
-            <dc:for-each>
-                <dc:context>
-                  <dc:call-macro name="range-filter">
+            <dc:macro name="waterlevels-fix">
+              <waterlevels>
+                <dc:for-each>
+                  <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}
+                          SELECT id AS out_id
+                          FROM outs
+                          WHERE artifact_id = ${a_id} AND name = 'longitudinal_section'
+                        </dc:statement>
+                        <dc:for-each>
+                          <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 description="{$river} {$a_creation} {$collection_name}">
+                              <dc:for-each>
+                                <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:for-each>
+                            </waterlevels>
+                          </dc:context>
+                        </dc:for-each>
+                      </dc:context>
+                    </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </waterlevels>
+            </dc:macro>
+
+            <dc:comment>
+              SHOW FLOODMAPS
+            </dc:comment>
+
+            <dc:macro name="flood-map">
+              <floodmap>
+                <dc:for-each>
+                  <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:for-each>
                           <dc:element name="${facet_name}">
                             <dc:attribute name="description" value="${facet_description}"/>
-                            <dc:attribute name="factory"     value="winfo"/>
+                            <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:attribute name="ids" value="${aid}"/>
+                            <dc:attribute name="out" value="floodmap"/>
                           </dc:element>
                         </dc:for-each>
                       </dc:context>
-                  </dc:call-macro>
-                </dc:context>
-            </dc:for-each>
-          </floodmap>
-        </dc:macro>
+                    </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </floodmap>
+            </dc:macro>
 
-        <dc:comment>
-          MINFO bedheight difference
-        </dc:comment>
+            <dc:comment>
+              MINFO bedheight difference
+            </dc:comment>
 
-        <dc:macro name="bed-difference">
-          <fix_longitudinal_section_curve>
-            <dc:for-each>
-                <dc:context>
-                  <dc:call-macro name="range-filter">
+            <dc:macro name="bed-difference">
+              <fix_longitudinal_section_curve>
+                <dc:for-each>
+                  <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}
+                          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:for-each>
-                            <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:for-each>
-                        </fix_longitudinal_section_curve>
-                        </dc:context>
-                    </dc:call-macro>
-                </dc:context>
-            </dc:for-each>
-          </fix_longitudinal_section_curve>
-        </dc:macro>
-
-        <dc:comment>
-          MINFO bedheight middle
-        </dc:comment>
-
-        <dc:macro name="bed-height">
-          <fix_vollmer_wq_curve>
-            <dc:for-each>
-                <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:for-each>
-                                <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:for-each>
-                        </fix_vollmer_wq_curve>
-                        </dc:context>
-                    </dc:call-macro>
-                </dc:context>
-            </dc:for-each>
-          </fix_vollmer_wq_curve>
-        </dc:macro>
-
-        <dc:macro name="floodmap-hws-user">
-                  <dc:context>
-                    <dc:statement>
-                      SELECT id AS out_id
-                      FROM outs
-                      WHERE artifact_id = ${a_id} AND name = 'floodmap'
-                    </dc:statement>
-                    <dc:for-each>
-                      <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 = 'floodmap.usershape'
-                          ORDER BY num ASC, name DESC
-                        </dc:statement>
-                        <own-hws>
+                        <fix_longitudinal_section_curve description="{$river} {$a_creation} {$collection_name}">
                           <dc:for-each>
                             <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="floodmap"/>
+                              <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:for-each>
-                        </own-hws>
+                        </fix_longitudinal_section_curve>
                       </dc:context>
-                    </dc:for-each>
+                    </dc:call-macro>
                   </dc:context>
-        </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:if test="dc:contains($artifact-outs, 'floodmap-hws')">
-          <dc:call-macro name="floodmap-hws-user"/>
-        </dc:if>
-      </dc:context>
-  </dc:call-macro>
+                </dc:for-each>
+              </fix_longitudinal_section_curve>
+            </dc:macro>
+
+            <dc:comment>
+              MINFO bedheight middle
+            </dc:comment>
+
+            <dc:macro name="bed-height">
+              <fix_vollmer_wq_curve>
+                <dc:for-each>
+                  <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 description="{$river} {$a_creation} {$collection_name}">
+                          <dc:for-each>
+                            <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:for-each>
+                        </fix_vollmer_wq_curve>
+                      </dc:context>
+                    </dc:call-macro>
+                  </dc:context>
+                </dc:for-each>
+              </fix_vollmer_wq_curve>
+            </dc:macro>
+
+            <dc:macro name="floodmap-hws-user">
+              <dc:context>
+                <dc:statement>
+                  SELECT id AS out_id
+                  FROM outs
+                  WHERE artifact_id = ${a_id} AND name = 'floodmap'
+                </dc:statement>
+                <dc:for-each>
+                  <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 = 'floodmap.usershape'
+                      ORDER BY num ASC, name DESC
+                    </dc:statement>
+                    <own-hws>
+                      <dc:for-each>
+                        <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="floodmap"/>
+                        </dc:element>
+                      </dc:for-each>
+                    </own-hws>
+                  </dc:context>
+                </dc:for-each>
+              </dc:context>
+            </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:if test="dc:contains($artifact-outs, 'floodmap-hws')">
+              <dc:call-macro name="floodmap-hws-user"/>
+            </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:if test="dc:contains($parameters,'load-system')">
+        <dc:comment>
+          Include System specific part when 'load-system' is in parameters.
+          -----------------------------------------------------------------
+        </dc:comment>
+        <dc:call-macro name="load-system"/>
+      </dc:if>
     </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:comment>
+        Include System specific part only if no user ID is given.
+        ---------------------------------------------------------
+      </dc:comment>
+      <dc:call-macro name="load-system"/>
     </dc:otherwise>
   </dc:choose>
+
 </datacage>
 </dc:template>

http://dive4elements.wald.intevation.org