<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output doctype-public="-//W3C//DTD Specification V2.10//EN" doctype-system="xmlspec.dtd"/>
    <xsl:template match="node() | @*">
        <xsl:copy>
            <xsl:apply-templates select="node() | @*"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="@xml:base"/>
    <xsl:template match="phrase[parent::ulist]">
        <item>
            <p>
                <xsl:apply-templates select="node() | @*"/>
            </p>
        </item>
    </xsl:template>
    <xsl:template match="phrase[@diff='del' and following-sibling::phrase[@diff='add']]">
        <xsl:variable name="deleted" select="normalize-space(.)"/>
        <xsl:variable name="added" select="normalize-space(following-sibling::phrase[1])"/>
        <xsl:choose>
            <xsl:when test="contains($added,$deleted)"/>
            <xsl:otherwise>
                <xsl:copy-of select="."/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="phrase[@diff='add' and preceding-sibling::phrase[@diff='del']]">
        <xsl:variable name="deleted" select="normalize-space(preceding-sibling::phrase[1])"/>
        <xsl:variable name="added" select="normalize-space(.)"/>
        <xsl:choose>
            <xsl:when test="contains($deleted,$added)">
                <xsl:value-of select="."/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:copy-of select="."/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="@diff[parent::altlocs]"/>
    <xsl:template match="phrase[ancestor::altlocs]">
        <xsl:value-of select="."/>
    </xsl:template>
</xsl:stylesheet>
