<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:tei="http://www.tei-c.org/ns/1.0" 
                xmlns:ct="http://www.comhartaighde.com/ns/1.0" 
                exclude-result-prefixes="tei ct"
                version="1.0">
    
<xsl:output method="text" omit-xml-declaration="yes" indent="no" />
    


<xsl:template match="//príomhshonraí/teideal[@xml:lang='ga']">
    <xsl:value-of select='normalize-space()'/>
</xsl:template>

<xsl:template match="//ceanntásc/príomhshonraí/údar">
    <xsl:for-each select="alt/ceanntásc/príomhshonraí/údar/duine">
       <xsl:value-of select="céadainm"/><xsl:text> </xsl:text><xsl:value-of select="sloinne"/>
       <xsl:if test="count(//ceanntásc/príomhshonraí/údar) &gt; 1">
           <xsl:if test="position() != last()">
              <xsl:text>, </xsl:text>
           </xsl:if>
       </xsl:if>
    </xsl:for-each>
</xsl:template>
    
<xsl:template match="//próifíl/aicmiú">
    <xsl:for-each select="//próifíl/aicmiú/eochairfhocail[@xml:lang='ga']/téarma">
       <xsl:value-of select="normalize-space()"/>
       <xsl:if test="count(//próifíl/aicmiú/eochairfhocail[@xml:lang='ga']/téarma) &gt; 1">
           <xsl:if test="position() != last()">
              <xsl:text>, </xsl:text>
           </xsl:if>
       </xsl:if>
    </xsl:for-each>
</xsl:template>
    
<xsl:template match="//léirmheas">
    <xsl:value-of select='normalize-space()'/>
    <xsl:text>  </xsl:text>
</xsl:template>
    
<xsl:template match="//corp">
    <xsl:value-of select='normalize-space()'/>
</xsl:template>
    

<xsl:template match="/">
     {  "title": "<xsl:apply-templates select="//príomhshonraí/teideal[@xml:lang='ga']"/>", 
        "authors": "<xsl:apply-templates select="//príomhshonraí/údar/duine"/>",
        "keywords": "<xsl:apply-templates select="//próifíl/aicmiú"/>",
        "DOI": "<xsl:text>http://dx.doi.org/10.18669/</xsl:text><xsl:value-of select="alt/ceanntásc/príomhshonraí/DOI"/>",
        "url": "http://www.comhartaighde.com/eagrain/<xsl:value-of select="//eagrán/@uimh"/>/<xsl:value-of select="//aitheantóir"/>/",
        "text": "<xsl:apply-templates select="//corp"/>" }
</xsl:template>
    

</xsl:stylesheet>