<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <!--

    XSL Flat File Conversion V0.2.0
    Copyright (C) 2002 by Friedhelm Duesterhoeft
    Generated with fx2sx.xsl

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

-->
  <xsl:output indent="yes"/>
  <xsl:template name="presentations">
    <xsl:param name="pos"/>
    <xsl:param name="eof"/>
    <xsl:param name="oldgroup"/>
    <xsl:call-template name="presentation">
      <xsl:with-param name="pos" select="$pos"/>
      <xsl:with-param name="eof" select="$eof"/>
      <xsl:with-param name="oldgroup" select="$oldgroup"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template name="presentation">
    <xsl:param name="pos"/>
    <xsl:param name="eof"/>
    <xsl:param name="oldgroup"/>
    <xsl:if test="$pos &lt;= $eof">
      <xsl:variable name="newgroup"/>
      <xsl:if test="$oldgroup = $newgroup">
        <xsl:variable name="old" select="row[$pos - 1]/column[1]/@value"/>
        <xsl:variable name="new" select="row[$pos]/column[1]/@value"/>
        <xsl:if test="not($old = $new)">
          <presentation name="{row[$pos]/column[1]/@value}">
            <xsl:call-template name="section">
              <xsl:with-param name="pos" select="$pos"/>
              <xsl:with-param name="eof" select="$eof"/>
              <xsl:with-param name="oldgroup" select="row[$pos]/column[1]/@value"/>
            </xsl:call-template>
          </presentation>
        </xsl:if>
        <xsl:call-template name="presentation">
          <xsl:with-param name="pos" select="$pos + 1"/>
          <xsl:with-param name="eof" select="$eof"/>
          <xsl:with-param name="oldgroup" select="$oldgroup"/>
        </xsl:call-template>
      </xsl:if>
    </xsl:if>
  </xsl:template>
  <xsl:template name="section">
    <xsl:param name="pos"/>
    <xsl:param name="eof"/>
    <xsl:param name="oldgroup"/>
    <xsl:if test="$pos &lt;= $eof">
      <xsl:variable name="newgroup" select="row[$pos]/column[1]/@value"/>
      <xsl:if test="$oldgroup = $newgroup">
        <xsl:variable name="old" select="row[$pos - 1]/column[2]/@value"/>
        <xsl:variable name="new" select="row[$pos]/column[2]/@value"/>
        <xsl:if test="not($old = $new)">
          <section name="{row[$pos]/column[2]/@value}">
            <xsl:call-template name="title">
              <xsl:with-param name="pos" select="$pos"/>
              <xsl:with-param name="eof" select="$eof"/>
              <xsl:with-param name="oldgroup" select="concat(row[$pos]/column[1]/@value,row[$pos]/column[2]/@value)"/>
            </xsl:call-template>
            <xsl:call-template name="page">
              <xsl:with-param name="pos" select="$pos"/>
              <xsl:with-param name="eof" select="$eof"/>
              <xsl:with-param name="oldgroup" select="concat(row[$pos]/column[1]/@value,row[$pos]/column[2]/@value)"/>
            </xsl:call-template>
          </section>
        </xsl:if>
        <xsl:call-template name="section">
          <xsl:with-param name="pos" select="$pos + 1"/>
          <xsl:with-param name="eof" select="$eof"/>
          <xsl:with-param name="oldgroup" select="$oldgroup"/>
        </xsl:call-template>
      </xsl:if>
    </xsl:if>
  </xsl:template>
  <xsl:template name="title">
    <xsl:param name="pos"/>
    <xsl:param name="eof"/>
    <xsl:param name="oldgroup"/>
    <xsl:if test="$pos &lt;= $eof">
      <xsl:variable name="newgroup" select="concat(row[$pos]/column[1]/@value,row[$pos]/column[2]/@value)"/>
      <xsl:if test="$oldgroup = $newgroup">
        <xsl:variable name="old" select="row[$pos - 1]/field/@content"/>
        <xsl:variable name="new" select="row[$pos]/field/@content"/>
        <xsl:if test="not($old = $new)">
          <title name="{row[$pos]/field/@content}"/>
        </xsl:if>
        <xsl:call-template name="title">
          <xsl:with-param name="pos" select="$pos + 1"/>
          <xsl:with-param name="eof" select="$eof"/>
          <xsl:with-param name="oldgroup" select="$oldgroup"/>
        </xsl:call-template>
      </xsl:if>
    </xsl:if>
  </xsl:template>
  <xsl:template name="page">
    <xsl:param name="pos"/>
    <xsl:param name="eof"/>
    <xsl:param name="oldgroup"/>
    <xsl:if test="$pos &lt;= $eof">
      <xsl:variable name="newgroup" select="concat(row[$pos]/column[1]/@value,row[$pos]/column[2]/@value)"/>
      <xsl:if test="$oldgroup = $newgroup">
        <xsl:variable name="old" select="row[$pos - 1]/column[3]/@value"/>
        <xsl:variable name="new" select="row[$pos]/column[3]/@value"/>
        <xsl:if test="not($old = $new)">
          <page name="{row[$pos]/column[3]/@value}">
            <xsl:call-template name="copyright">
              <xsl:with-param name="pos" select="$pos"/>
              <xsl:with-param name="eof" select="$eof"/>
              <xsl:with-param name="oldgroup" select="concat(row[$pos]/column[1]/@value,row[$pos]/column[2]/@value,row[$pos]/column[3]/@value)"/>
            </xsl:call-template>
            <xsl:call-template name="item">
              <xsl:with-param name="pos" select="$pos"/>
              <xsl:with-param name="eof" select="$eof"/>
              <xsl:with-param name="oldgroup" select="concat(row[$pos]/column[1]/@value,row[$pos]/column[2]/@value,row[$pos]/column[3]/@value)"/>
            </xsl:call-template>
          </page>
        </xsl:if>
        <xsl:call-template name="page">
          <xsl:with-param name="pos" select="$pos + 1"/>
          <xsl:with-param name="eof" select="$eof"/>
          <xsl:with-param name="oldgroup" select="$oldgroup"/>
        </xsl:call-template>
      </xsl:if>
    </xsl:if>
  </xsl:template>
  <xsl:template name="copyright">
    <xsl:param name="pos"/>
    <xsl:param name="eof"/>
    <xsl:param name="oldgroup"/>
    <xsl:if test="$pos &lt;= $eof">
      <xsl:variable name="newgroup" select="concat(row[$pos]/column[1]/@value,row[$pos]/column[2]/@value,row[$pos]/column[3]/@value)"/>
      <xsl:if test="$oldgroup = $newgroup">
        <copyright by="Friedhelm Duesterhoeft"/>
        <xsl:call-template name="copyright">
          <xsl:with-param name="pos" select="$pos + 1"/>
          <xsl:with-param name="eof" select="$eof"/>
          <xsl:with-param name="oldgroup" select="$oldgroup"/>
        </xsl:call-template>
      </xsl:if>
    </xsl:if>
  </xsl:template>
  <xsl:template name="item">
    <xsl:param name="pos"/>
    <xsl:param name="eof"/>
    <xsl:param name="oldgroup"/>
    <xsl:if test="$pos &lt;= $eof">
      <xsl:variable name="newgroup" select="concat(row[$pos]/column[1]/@value,row[$pos]/column[2]/@value,row[$pos]/column[3]/@value)"/>
      <xsl:if test="$oldgroup = $newgroup">
        <item name="{row[$pos]/column[4]/@value}">
          <xsl:call-template name="item2">
            <xsl:with-param name="pos" select="$pos"/>
            <xsl:with-param name="eof" select="$eof"/>
            <xsl:with-param name="oldgroup" select="$oldgroup"/>
          </xsl:call-template>
        </item>
        <xsl:call-template name="item">
          <xsl:with-param name="pos" select="$pos + 1"/>
          <xsl:with-param name="eof" select="$eof"/>
          <xsl:with-param name="oldgroup" select="$oldgroup"/>
        </xsl:call-template>
      </xsl:if>
    </xsl:if>
  </xsl:template>
  <xsl:template name="item2">
    <xsl:param name="pos"/>
    <xsl:param name="eof"/>
    <xsl:param name="oldgroup"/>
    <item2 name="{row[$pos]/column[5]}"/>
  </xsl:template>
  <xsl:template match="rows">
    <presentations>
      <xsl:call-template name="presentations">
        <xsl:with-param name="pos" select="1"/>
        <xsl:with-param name="eof" select="count(row)"/>
      </xsl:call-template>
    </presentations>
  </xsl:template>
  <xsl:template match="/">
    <xsl:apply-templates select="rows"/>
  </xsl:template>
</xsl:stylesheet>
