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

    <xsl:output method="xml" encoding="UTF-8" />

    <xsl:template match="@*|node()" mode="logbook">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    
    <!-- updates the formedtree version and the version nr -->
    <xsl:template match="cases">
    <cases formed-type="http://mpuls.intevation.de/formed/jmd-case/2011-06-16/10:08" version="5">
        <xsl:apply-templates/>
    </cases>
    </xsl:template>

    <!-- feld loeschen -->
    <xsl:template match="anzahl_geschwister" />

    <xsl:template match="master">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>

          <!-- see also: issue2157 and upgrade/1.1/02_angaben_geschwister -->
          <xsl:variable name="anzahl_geschwister" select="./anzahl_geschwister/text()"/>
          <xsl:if test="$anzahl_geschwister">
            <angaben_geschwister>
                <xsl:value-of select="$anzahl_geschwister"/>
            </angaben_geschwister>
          </xsl:if>
          
        </xsl:copy>
    </xsl:template>
    
    <!-- see also: issue2039 and upgrade/1.1/05_integrationskurs.sql -->
    <xsl:template match="aktuelle_situation">
        <aktuelle_situation>
            <xsl:choose>
                <xsl:when test=". = '-1' and ../aktuelle_massnahme_art = '3'">
                    11
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="."/>
                </xsl:otherwise>
            </xsl:choose>
        </aktuelle_situation>
    </xsl:template>
    
    <xsl:template match="aktuelle_massnahme_art">
        <aktuelle_massnahme_art>
            <xsl:choose>
                <xsl:when test=". = '3'">
                    -1
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="."/>
                </xsl:otherwise>
            </xsl:choose>
        </aktuelle_massnahme_art>
    </xsl:template>

    <xsl:template match="@*|node()">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>