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

<xsl:template match="title/title">
    <span class="workTitle"><xsl:value-of select="."/></span>
</xsl:template>

<xsl:template match="titleEN/title">
    <span class="workTitle"><xsl:value-of select="."/></span>
</xsl:template>
    
<xsl:template match="i">
    <i><xsl:value-of select="."/></i>
</xsl:template>
    
<xsl:template match="title">
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="titleEN">
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="/">
    <xsl:if test="edition/article[@article_type='Eagarfhocal']">
        <section id="editorial">
            <h1>
                <xsl:choose>
                    <xsl:when test="$lang='en'">
                        <xsl:text>Editorial</xsl:text>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:text>Eagarfhocal</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
            </h1>
            <xsl:for-each select="edition/article[@article_type='Eagarfhocal']">
                <xsl:sort select="@sequence" order="ascending" data-type="number"/>
                <div class="article">
                    <xsl:element name="a">
                    <xsl:attribute name="href">
                        <xsl:text>/eagrain/</xsl:text>
                        <xsl:value-of select="/edition/@number"/>
                        <xsl:text>/</xsl:text>
                        <xsl:value-of select="@identifier"/>
                        <xsl:text>/</xsl:text>
                        <xsl:if test="$lang='en'">
                            <xsl:text>en/</xsl:text>
                        </xsl:if>
                    </xsl:attribute>
                        <h2><span class="tocOrder"><xsl:value-of select="@sequence"/><xsl:text>. </xsl:text></span><xsl:apply-templates select="title"/></h2>
                        <p class="authorNames"><xsl:value-of select="authors"/></p>
                    </xsl:element>
                </div>
            </xsl:for-each>
        </section>
    </xsl:if>
    <xsl:if test="edition/article[@article_type='Alt Taighde']">
        <section id="researchArticles">
            <h1>
                <xsl:choose>
                    <xsl:when test="$lang='en'">
                        <xsl:text>Research Articles</xsl:text>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:text>Ailt Taighde</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
            </h1>
            <xsl:for-each select="edition/article[@article_type='Alt Taighde']">
                <xsl:sort select="@sequence" order="ascending" data-type="number"/>
                <div class="article">
                    <xsl:element name="a">
                    <xsl:attribute name="href">
                        <xsl:text>/eagrain/</xsl:text>
                        <xsl:value-of select="/edition/@number"/>
                        <xsl:text>/</xsl:text>
                        <xsl:value-of select="@identifier"/>
                        <xsl:text>/</xsl:text>
                        <xsl:if test="$lang='en'">
                            <xsl:text>en/</xsl:text>
                        </xsl:if>
                    </xsl:attribute>
                        <h2>
                            <xsl:element name="span">
                                <xsl:attribute name="class">tocOrder</xsl:attribute>
                                <xsl:if test="@sequence &gt; 9">
                                    <xsl:attribute name="style">margin-right:0;</xsl:attribute>
                                </xsl:if>
                                <xsl:value-of select="@sequence"/><xsl:text>. </xsl:text>
                            </xsl:element>
                            <xsl:choose>
                                <xsl:when test="$lang='en'">
                                    <xsl:apply-templates select="titleEN"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:apply-templates select="title"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </h2>
                        <p class="authorNames"><xsl:value-of select="authors"/></p>
                    </xsl:element>
                </div>
            </xsl:for-each>
        </section>
    </xsl:if>
    <xsl:if test="edition/article[@article_type='Léirmheas']">
        <section id="reviews">
            <h1>
                <xsl:choose>
                    <xsl:when test="$lang='en'">
                        <xsl:text>Reviews</xsl:text>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:text>Léirmheasanna</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
            </h1>
            <xsl:for-each select="edition/article[@article_type='Léirmheas']">
                <xsl:sort select="@sequence" order="ascending" data-type="number"/>
                <div class="article">
                    <xsl:element name="a">
                    <xsl:attribute name="href">
                        <xsl:text>/eagrain/</xsl:text>
                        <xsl:value-of select="/edition/@number"/>
                        <xsl:text>/</xsl:text>
                        <xsl:value-of select="@identifier"/>
                        <xsl:text>/</xsl:text>
                        <xsl:if test="$lang='en'">
                            <xsl:text>en/</xsl:text>
                        </xsl:if>
                    </xsl:attribute>
                        <h2><span class="tocOrder"><xsl:value-of select="@sequence"/><xsl:text>. </xsl:text></span>
                            <xsl:choose>
                                <xsl:when test="count(title) &gt; 1">
                                    <xsl:for-each select="title">
                                        <xsl:apply-templates/>
                                        <xsl:if test="position() = last()-1">
                                        <br/>
                                        </xsl:if>
                                    </xsl:for-each>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:apply-templates select="title"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </h2>
                        <p class="reviewers"><span class="reviewerLabel">
                            <xsl:choose>
                                <xsl:when test="$lang='en'">
                                    <xsl:text>Review</xsl:text>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:text>Léirmheas</xsl:text>
                                </xsl:otherwise>
                            </xsl:choose>
                            <xsl:text>: </xsl:text>
                        </span><xsl:value-of select="authors"/></p>
                    </xsl:element>
                </div>
            </xsl:for-each>
        </section>
    </xsl:if>
</xsl:template>
    
</xsl:stylesheet>