<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.tei-c.org/ns/1.0" version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />
    
<xsl:include href="_variables.xsl" />
    
<!--remove namespace from all nodes-->
<xsl:template match="*" name="identity">
  <xsl:element name="{name()}">
    <xsl:apply-templates select="node()|@*" />
  </xsl:element>
</xsl:template>

<!--copy all content-->
<xsl:template match="node()|@*" priority="-2">
  <xsl:copy>
    <xsl:apply-templates select="node()|@*" />
  </xsl:copy>
</xsl:template>
    
    
<!--major elements-->
<xsl:template match="alt">
    <TEI version="5.0" xmlns="http://www.tei-c.org/ns/1.0" xml:lang="ga"><xsl:apply-templates/></TEI>
</xsl:template>
    
<xsl:template match="ceanntásc">
    <teiHeader><fileDesc><xsl:apply-templates/></fileDesc></teiHeader>
</xsl:template>
    
<xsl:template match="príomhshonraí">
    <titleStmt><xsl:apply-templates/></titleStmt>
</xsl:template>    
    
<xsl:template match="corp/achoimre[@xml:lang='ga']">
    <div type="abstract" xml:lang="ga"><xsl:apply-templates/></div>
</xsl:template>
    
<xsl:template match="corp/achoimre[@xml:lang='en']">
    <div type="abstract" xml:lang="en"><xsl:apply-templates/></div>
</xsl:template>
    
<xsl:template match="corp/corpAilt">
    <div type="articleContent"><xsl:apply-templates/><xsl:apply-templates select="//div[@type='endnotes']" /></div>
</xsl:template>
    
<xsl:template match="corp/tagairtí">
    <div type="citations"><xsl:apply-templates/></div>
</xsl:template>


<!--main text heading-->
<xsl:template match="alt/téacs/corp">
    <xsl:choose>
        <xsl:when test="(//príomhshonraí/cineálAilt[@xml:lang='ga']) = 'Léirmheas'">
            <xsl:for-each select="//léirmheas/bibl">
                <head><xsl:for-each select="teideal"><xsl:apply-templates/></xsl:for-each></head>
                <xsl:if test="údar">
                    <p type="authors">
                        <xsl:for-each select="údar/duine">
                           <xsl:value-of select="."/>
                           <xsl:if test="count(//ceanntásc/léirmheas/bibl/údar) &gt; 2">
                               <xsl:if test="position() != last()-1 and position() != last()"><xsl:text>, </xsl:text></xsl:if>
                           </xsl:if>
                           <xsl:if test="count(//ceanntásc/léirmheas/bibl/údar) &gt; 1">
                               <xsl:if test="position() = last()-1"><xsl:text> agus </xsl:text></xsl:if>
                           </xsl:if>
                        </xsl:for-each>
                    </p>
                </xsl:if>
                <xsl:if test="eagarthóir">
                    <p type="editors">
                        <xsl:for-each select="eagarthóir/duine">
                           <xsl:value-of select="."/>
                           <xsl:if test="count(//ceanntásc/léirmheas/bibl/eagarthóir) &gt; 2">
                               <xsl:if test="position() != last()-1 and position() != last()"><xsl:text>, </xsl:text></xsl:if>
                           </xsl:if>
                           <xsl:if test="count(//ceanntásc/léirmheas/bibl/eagarthóir) &gt; 1">
                               <xsl:if test="position() = last()-1"><xsl:text> agus </xsl:text></xsl:if>
                           </xsl:if>
                        </xsl:for-each>
                        <xsl:choose> 
                            <xsl:when test="count(eagarthóir) &gt; 1"><xsl:text> (eagí)</xsl:text></xsl:when>
                            <xsl:otherwise><xsl:text> (eag.)</xsl:text></xsl:otherwise>
                        </xsl:choose> 
                    </p>
                </xsl:if>
                <xsl:if test="aistritheoir">
                    <p type="translators">
                        <xsl:for-each select="aistritheoir/duine">
                           <xsl:value-of select="."/>
                           <xsl:if test="count(//ceanntásc/léirmheas/bibl/aistritheoir) &gt; 2">
                               <xsl:if test="position() != last()-1 and position() != last()"><xsl:text>, </xsl:text></xsl:if>
                           </xsl:if>
                           <xsl:if test="count(//ceanntásc/léirmheas/bibl/aistritheoir) &gt; 1">
                               <xsl:if test="position() = last()-1"><xsl:text> agus </xsl:text></xsl:if>
                           </xsl:if>
                        </xsl:for-each>
                        <xsl:text> (aist.)</xsl:text>
                    </p>
                </xsl:if>
                <p type="reviewItemMeta"><xsl:for-each select="foilsitheoir"><xsl:apply-templates /></xsl:for-each> (<xsl:value-of select="dáta" />) <xsl:if test="leathanaigh"> | <xsl:value-of select="leathanaigh" /> lch</xsl:if><xsl:if test="ISBN"> | ISBN: <xsl:value-of select="ISBN" /></xsl:if><xsl:if test="praghas"> | <xsl:value-of select="praghas" /></xsl:if></p>
            </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
            <head><xsl:apply-templates select="//príomhshonraí/teideal[@xml:lang='ga']"/></head>
            <p type="authors"><xsl:copy-of select="$authorNames"/></p>
        </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates/>
</xsl:template>
    
    
<!--components-->
<xsl:template match="ceann">
    <head><xsl:apply-templates/></head>
</xsl:template>
    
<xsl:template match="corp">
    <body><xsl:apply-templates/></body>
</xsl:template>
    
<xsl:template match="téacs">
    <text><xsl:apply-templates/></text>
</xsl:template>
    
<xsl:template match="athfhriotal">
    <quote><xsl:apply-templates/></quote>
</xsl:template>
    
<xsl:template match="véarsa">
    <lg><xsl:apply-templates/></lg>
</xsl:template>
    
<xsl:template match="teideal">
    <title><xsl:apply-templates/></title>
</xsl:template>
    
<xsl:template match="príomhshonraí/teideal">
    <xsl:element name="title">
        <xsl:attribute name="xml:lang"><xsl:value-of select="@xml:lang"/></xsl:attribute>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>
    
<xsl:template match="údar">
    <author><xsl:apply-templates/></author>
</xsl:template>
    
<xsl:template match="duine">
    <xsl:element name="persName">
        <xsl:if test="@beathaisnéis">
            <xsl:attribute name="target"><xsl:value-of select="@beathaisnéis"/></xsl:attribute>
        </xsl:if>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>
    
<xsl:template match="céadainm">
    <forename><xsl:apply-templates/></forename>
</xsl:template>
    
<xsl:template match="sloinne">
    <surname><xsl:apply-templates/></surname>
</xsl:template>

<xsl:template match="cleamhnacht">
    <xsl:element name="affiliation">
        <xsl:attribute name="xml:lang"><xsl:value-of select="@xml:lang"/></xsl:attribute>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>
 
<xsl:template match="ríomhphost">
    <email><xsl:apply-templates/></email>
</xsl:template>
    
<xsl:template match="beathaisnéis">
    <note type="biographicalNote"><xsl:apply-templates/></note>
</xsl:template>
    
<xsl:template match="DOI">
    <idno type="DOI"><xsl:apply-templates/></idno>
</xsl:template>
    
<xsl:template match="eagrán">
    <editionStmt>
        <xsl:element name="edition">
            <xsl:attribute name="n"><xsl:value-of select="@uimh"/></xsl:attribute>
            <xsl:apply-templates/>
        </xsl:element>
    </editionStmt> 
</xsl:template>
    
<xsl:template match="foilseachán">
    <publicationStmt><xsl:apply-templates/></publicationStmt>
</xsl:template>
    
<xsl:template match="foilsitheoir">
    <publisher><xsl:apply-templates/></publisher>
</xsl:template>
    
<xsl:template match="ISSN">
    <idno type="ISSN"><xsl:apply-templates/></idno>
</xsl:template>
    
<xsl:template match="dáta">
    <date><xsl:apply-templates/></date>
</xsl:template>
    
<xsl:template match="bliain">
    <year><xsl:apply-templates/></year>
</xsl:template>
    
<xsl:template match="mí">
    <month><xsl:apply-templates/></month>
</xsl:template>
    
<xsl:template match="lá">
    <day><xsl:apply-templates/></day>
</xsl:template>
    
<xsl:template match="foilseachán/áit">
    <pubPlace><xsl:apply-templates/></pubPlace>
</xsl:template>
    
<xsl:template match="blurba">
    <notesStmt><xsl:apply-templates/></notesStmt>
</xsl:template>
    
<xsl:template match="blurba/curSíos">
    <xsl:element name="note">
        <xsl:attribute name="xml:lang"><xsl:value-of select="@xml:lang"/></xsl:attribute>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>
    
<xsl:template match="foinse">
    <sourceDesc><xsl:apply-templates/></sourceDesc>
</xsl:template>
    
<xsl:template match="ionchódú">
    <encodingDesc><xsl:apply-templates/></encodingDesc>
</xsl:template>
    
<xsl:template match="eagarthóireacht">
    <editorialDecl><xsl:apply-templates/></editorialDecl>
</xsl:template>
    
<xsl:template match="stílTagartha">
    <citationStyle><xsl:apply-templates/></citationStyle>
</xsl:template>
    
<xsl:template match="infhaighteacht">
    <xsl:element name="availability">
        <xsl:attribute name="status"><xsl:if test="(@stádas)='teoranta'">restricted</xsl:if></xsl:attribute>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>
    
<xsl:template match="ceadúnas">
    <xsl:element name="licence">
        <xsl:attribute name="xml:lang"><xsl:value-of select="@xml:lang"/></xsl:attribute>
        <xsl:attribute name="type"><xsl:if test="@cineál='údar'">author</xsl:if></xsl:attribute>
        <xsl:attribute name="target">http://www.comhartaighde.com/eolas/coipcheart/</xsl:attribute>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>
    
<xsl:template match="próifíl">
    <profileDesc><xsl:apply-templates/></profileDesc>
</xsl:template>
    
<xsl:template match="aicmiú">
    <textClass><xsl:apply-templates/></textClass>
</xsl:template>
    
<xsl:template match="eochairfhocail">
    <xsl:element name="keywords">
        <xsl:attribute name="xml:lang"><xsl:value-of select="@xml:lang"/></xsl:attribute>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>
    
<xsl:template match="téarma">
    <term><xsl:apply-templates/></term>
</xsl:template>
    
<xsl:template match="logainm">
    <xsl:element name="placeName">
        <xsl:if test="@sprioc">
            <xsl:attribute name="target"><xsl:value-of select="@sprioc"/></xsl:attribute>
        </xsl:if>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>
    
<xsl:template match="léirmheastóirí">
    <xsl:apply-templates/>
</xsl:template>
    
<xsl:template match="léirmheastóirí/p">
    <p type="reviewerSignature"><xsl:apply-templates/></p>
</xsl:template>
    
<xsl:template match="liosta[@cineál='uimhrithe']">
    <list rend="numbered">
        <xsl:for-each select="mír">
            <item><xsl:apply-templates /></item>
        </xsl:for-each>
    </list>
</xsl:template>
    
<xsl:template match="liosta[@cineál='urchair']">
    <list rend="bulleted">
        <xsl:for-each select="mír">
            <item><xsl:apply-templates /></item>
        </xsl:for-each>
    </list>
</xsl:template>
    
    
<!--links-->
<xsl:template match="tagairt">
    <xsl:element name="ref">
        <xsl:attribute name="type">citation</xsl:attribute>
        <xsl:attribute name="target"><xsl:value-of select="@sprioc"/></xsl:attribute>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>
    
<xsl:template match="nasc">
    <xsl:element name="ref">
        <xsl:attribute name="target"><xsl:value-of select="@sprioc"/></xsl:attribute>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>
    
    
<!--typography-->
<xsl:template match="láidir">
    <strong><xsl:apply-templates/></strong>
</xsl:template>
    
<xsl:template match="béim">
    <emph><xsl:apply-templates/></emph>
</xsl:template>
    
<xsl:template match="iasacht">
    <foreign><xsl:apply-templates/></foreign>
</xsl:template>
    
<xsl:template match="mioncheannlitreacha">
    <hi rend="smallCaps"><xsl:value-of select="."/></hi>
</xsl:template>
    
<xsl:template match="briseadhLíne">
    <lb/>
</xsl:template>  

<xsl:template match="amparsan">
    <xsl:text>&amp;</xsl:text>
</xsl:template> 
    
<xsl:template match="níosMó">
    <xsl:text>&gt;</xsl:text>
</xsl:template> 
    
<xsl:template match="níosLú">
    <xsl:text>&lt;</xsl:text>
</xsl:template> 
    
<xsl:template match="tagairt/amparsan">
    <xsl:text>&amp;</xsl:text>
</xsl:template>

<xsl:template match="nasc/amparsan">
    <xsl:text>&amp;</xsl:text>
</xsl:template>
    
    
<!--citations-->
<xsl:template match="liostaBibl">
    <listBibl><xsl:apply-templates/></listBibl>
</xsl:template>
    
<xsl:template match="lonnaíocht">
    <xsl:element name="settlement">
        <xsl:attribute name="location"><xsl:value-of select="@suíomh"/></xsl:attribute>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>
    
<xsl:template match="taisclann">
    <repository><xsl:apply-templates/></repository>
</xsl:template>
    
<xsl:template match="lámhscríbhinn">
    <msDesc><msIdentifier><idno><xsl:apply-templates/></idno></msIdentifier></msDesc>
</xsl:template>
    
    
<!--reviews-->
<xsl:template match="leathanaigh">
    <pages><xsl:apply-templates/></pages>
</xsl:template>
    
<xsl:template match="praghas">
    <price><xsl:apply-templates/></price>
</xsl:template>
    
    
<!--multimedia-->
<xsl:template match="fuaim|físeán">
    <xsl:for-each select="comhad">
        <xsl:element name="media">
            <xsl:attribute name="mimeType"><xsl:value-of select="@mimeType"/></xsl:attribute>
            <xsl:attribute name="url"><xsl:text>http://www.comhartaighde.com</xsl:text><xsl:value-of select="@url"/></xsl:attribute>
            <xsl:attribute name="dur"><xsl:value-of select="@fad"/></xsl:attribute>
        </xsl:element>
    </xsl:for-each>
    <xsl:apply-templates/>
</xsl:template>
    
<xsl:template match="fuaim/curSíos|físeán/curSíos">
    <desc><xsl:apply-templates/></desc>
</xsl:template>
    
<xsl:template match="figiúr">
    <figure>
        <xsl:for-each select="grafaic[@cuspóir='original-size']">
            <xsl:element name="graphic">
                <xsl:attribute name="url"><xsl:text>http://www.comhartaighde.com</xsl:text><xsl:value-of select="@url"/></xsl:attribute>
            </xsl:element>
        </xsl:for-each>
        <xsl:apply-templates/>
    </figure>
</xsl:template>
    
<xsl:template match="figiúr/curSíos">
    <figDesc><xsl:apply-templates/></figDesc>
</xsl:template>
    

<!--tables-->
<xsl:template match="tábla">
    <table><xsl:apply-templates/></table>
</xsl:template>
    
<xsl:template match="sraith">
    <xsl:element name="row">
        <xsl:if test="@ról='lipéad'">
            <xsl:attribute name="role">label</xsl:attribute>
        </xsl:if>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>
    
<xsl:template match="cill">
    <xsl:element name="cell">
        <xsl:if test="@ról='lipéad'">
            <xsl:attribute name="role">label</xsl:attribute>
        </xsl:if>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>
    

<!--nodes to be removed-->
<xsl:template match="aitheantóir"/>
<xsl:template match="cineálAilt"/>
<xsl:template match="gramadach"/>
<xsl:template match="léirmheas"/>
<xsl:template match="comhad"/>
<xsl:template match="grafaic"/>
    
    
</xsl:stylesheet>