<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:preserve-space elements="note noteText"/>
    <xsl:strip-space elements="ling"/>
    <xsl:output method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" encoding="UTF-8"/>
    <xsl:template match="*">
        <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="xref"/>
    <xsl:template match="title"/>
    <xsl:template match="author"/>
    <xsl:template match="filename"/>
    <xsl:template match="encyclopedia"/>
    <xsl:template match="encycEntry"/>
    <xsl:template match="title" mode="title">
        <xsl:apply-templates mode="title"/>
    </xsl:template>
    <xsl:template match="author" mode="title">
        <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="number"/>
    <xsl:template match="/">
        <html>
            <head>
                <title>The Annotated Afanas′ev: <xsl:choose>
                        <xsl:when test="/tale">
                            <xsl:apply-templates select="/tale/title" mode="title"/>
                            <xsl:text> (</xsl:text>
                            <xsl:value-of select="/tale/number"/>
                            <xsl:text>)</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:apply-templates select="/*/title" mode="title"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </title>
                <meta http-equiv="Content-Type" content="application/xhtml+xml;charset=UTF-8"/>
                <link href="aa.css" rel="stylesheet" type="text/css"/>
            </head>
            <body onload="javascript:self.focus()">
                <p
                    style="font-size: large; font-weight: bold; font-family: sans-serif; text-align:center;">
                    <a href="./index.html" target="_top">The Annotated Afanas′ev Library</a>
                </p>
                <h1>
                    <xsl:choose>
                        <xsl:when test="/tale">
                            <xsl:apply-templates select="/tale/title" mode="title"/>
                            <xsl:text> (</xsl:text>
                            <xsl:value-of select="/tale/number"/>
                            <xsl:text>)</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:apply-templates select="/*/title" mode="title"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </h1>
                <xsl:if test="not(/tale)">
                    <h2>
                        <xsl:apply-templates select="/*/author" mode="title"/>
                    </h2>
                </xsl:if>
                <xsl:apply-templates select="/*/encyclopedia" mode="title"/>
                <xsl:apply-templates/>
                <hr/>
                <p>
                    <xsl:variable name="tempa">
                        <xsl:choose>
                            <xsl:when test="/tale">
                                <xsl:text>./a</xsl:text>
                                <xsl:value-of select="/tale/number"/>
                                <xsl:text>_main.html</xsl:text>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="/*/filename"/>
                                <xsl:text>_main.html</xsl:text>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:variable>
                    <a href="{$tempa}" target="_top">Go to top</a>
                    <xsl:text> | </xsl:text>
                    <a href="./index.html" target="_top">Go to main page</a>
                </p>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="tale">
        <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="p">
        <p style="line-height: 1.4em">
            <xsl:apply-templates/>
        </p>
    </xsl:template>
    <xsl:template match="note">
        <xsl:variable name="temp">
            <xsl:choose>
                <xsl:when test="/tale">
                    <xsl:text>a</xsl:text>
                    <xsl:value-of select="/tale/number"/>
                    <xsl:text>_commentary.html#comment</xsl:text>
                    <xsl:number level="any"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="/*/filename"/>
                    <xsl:text>_commentary.html#comment</xsl:text>
                    <xsl:number level="any"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="temp1">
            <xsl:text>comment</xsl:text>
            <xsl:number level="any"/>
        </xsl:variable>
        <xsl:apply-templates/>
        <sup style="line-height: 0">
            <xsl:text>(</xsl:text>
            <a href="{$temp}" name="{$temp1}" target="commentary">
                <xsl:number level="any"/>
            </a>
            <xsl:text>)</xsl:text>
        </sup>
        <xsl:if test="preceding-sibling::line">
            <br/>
        </xsl:if>
    </xsl:template>
    <xsl:template match="ling">
        <xsl:variable name="temp">
            <xsl:choose>
                <xsl:when test="/tale">
                    <xsl:text>a</xsl:text>
                    <xsl:value-of select="/tale/number"/>
                    <xsl:text>_ling.html#ling</xsl:text>
                    <xsl:number level="any"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="/*/filename"/>
                    <xsl:text>_ling.html#ling</xsl:text>
                    <xsl:number level="any"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="temp1">
            <xsl:text>ling</xsl:text>
            <xsl:number level="any"/>
        </xsl:variable>
        <a name="{$temp1}" href="{$temp}" target="ling">
            <xsl:apply-templates select="lingText"/>
        </a>
    </xsl:template>
    <xsl:template match="lingText">
        <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="quote">
        <xsl:text> "</xsl:text>
        <xsl:apply-templates/>
        <xsl:text>" </xsl:text>
    </xsl:template>
    <xsl:template match="citation">
        <em>
            <xsl:apply-templates/>
        </em>
    </xsl:template>
    <xsl:template match="bookTitle">
        <cite>
            <xsl:apply-templates/>
        </cite>
    </xsl:template>
    <xsl:template match="gloss">
        <xsl:text> '</xsl:text>
        <xsl:apply-templates/>
        <xsl:text>' </xsl:text>
    </xsl:template>
    <xsl:template match="morphology">
        <em>
            <xsl:apply-templates/>
        </em>
    </xsl:template>
    <xsl:template match="note/noteExplanation"/>
    <xsl:template match="lg">
        <p>
            <xsl:apply-templates/>
        </p>
    </xsl:template>
    <xsl:template match="line[not(position()=last())][not(following-sibling::note)]">
        <xsl:apply-templates/>
        <br/>
    </xsl:template>
    <xsl:template match="line[not(position()=last())][following-sibling::note]">
        <xsl:apply-templates/>
        <br/>
    </xsl:template>
    <xsl:template match="encyclopedia" mode="title">
        <p>
            <strong>Encyclopedia Entries:</strong>
            <xsl:text> </xsl:text>
            <xsl:apply-templates mode="title"/>
        </p>
    </xsl:template>
    <xsl:template match="encycEntry" mode="title">
        <a href="encyclopedia/encyclopedia.html?encyclopedia_{@link}" target="encyclopedia"><xsl:apply-templates/></a>
        <xsl:if test="following-sibling::encycEntry">
            <xsl:text>, </xsl:text>
        </xsl:if>
    </xsl:template>
    <xsl:template match="note" mode="title">
        <xsl:variable name="temp">
            <xsl:choose>
                <xsl:when test="/tale">
                    <xsl:text>a</xsl:text>
                    <xsl:value-of select="/tale/number"/>
                    <xsl:text>_commentary.html#comment</xsl:text>
                    <xsl:number level="any"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="/*/filename"/>
                    <xsl:text>_commentary.html#comment</xsl:text>
                    <xsl:number level="any"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="temp1">
            <xsl:text>comment</xsl:text>
            <xsl:number level="any"/>
        </xsl:variable>
        <xsl:apply-templates/>
        <sup style="line-height: 0">
            <xsl:text>(</xsl:text>
            <a href="{$temp}" name="{$temp1}" target="commentary">
                <xsl:number level="any"/>
            </a>
            <xsl:text>)</xsl:text>
        </sup>
    </xsl:template>
    <xsl:template match="noteExplanation" mode="title"/>
    <xsl:template match="noteText" mode="title">
        <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="ling" mode="title">
        <xsl:apply-templates mode="title"/>
    </xsl:template>
    <xsl:template match="lingText" mode="title">
        <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="lingExplanation" mode="title"/>
</xsl:stylesheet>
