<commit_before><?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fn="http://www.w3.org/2005/xpath-functions"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:ae="http://www.ebi.ac.uk/arrayexpress/XSLT/Extension"
                xmlns:aejava="java:uk.ac.ebi.arrayexpress.utils.saxon.ExtFunctions"
                xmlns:search="java:uk.ac.ebi.arrayexpress.utils.saxon.search.SearchExtension"
                xmlns:html="http://www.w3.org/1999/xhtml"
                extension-element-prefixes="ae aejava search html fn xs"
                exclude-result-prefixes="ae aejava search html fn xs"
                version="2.0">

    <xsl:param name="accession"/>
    <xsl:param name="filename"/>

    <xsl:param name="host"/>
    <xsl:param name="basepath"/>
    <xsl:param name="userid"/>

    <xsl:variable name="vBaseUrl">http://<xsl:value-of select="$host"/><xsl:value-of select="$basepath"/></xsl:variable>

    <xsl:variable name="vPermittedColType" select="fn:tokenize('source name,characteristics,unit,factorvalue,factor value,array data file,derived array data file,array data matrix file,derived array data matrix file', '\s*,\s*')"/>
    <xsl:variable name="vPermittedComment" select="fn:tokenize('sample_description,sample_source_name', '\s*,\s*')"/>
    <xsl:variable name="vHeader" select="/table/row[col[1] = 'Source Name'][1]"/>
    <xsl:variable name="vAccession" select="fn:upper-case($accession)"/>
    <xsl:variable name="vMetaData" select="search:queryIndex('experiments', fn:concat('visible:true accession:', $accession, if ($userid) then fn:concat(' userid:(', $userid, ')') else ''))[accession = $vAccession]" />

    <xsl:output omit-xml-declaration="yes" method="html"
                indent="no" encoding="ISO-8859-1" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>

    <xsl:include href="ae-html-page.xsl"/>

    <xsl:template match="/">
        <html lang="en">
            <xsl:call-template name="page-header">
                <xsl:with-param name="pTitle">SDRF | <xsl:value-of select="$vAccession"/> | Experiments | ArrayExpress Archive | EBI</xsl:with-param>
                <xsl:with-param name="pExtraCode">
                    <link rel="stylesheet" href="{$basepath}/assets/stylesheets/ae_sdrf_view_20.css" type="text/css"/>
                    <script src="{$basepath}/assets/scripts/jquery-1.4.2.min.js" type="text/javascript"/>
                    <script src="{$basepath}/assets/scripts/jquery.cookie-1.0.js" type="text/javascript"/>
                    <script src="{$basepath}/assets/scripts/ae_common_20.js" type="text/javascript"/>
                    <script src="{$basepath}/assets/scripts/ae_sdrf_view_20.js" type="text/javascript"/>
                </xsl:with-param>
            </xsl:call-template>
            <xsl:call-template name="page-body"/>
        </html>
    </xsl:template>

    <xsl:template name="ae-contents">
        <xsl:choose>
            <xsl:when test="exists($vHeader) and exists($vMetaData)">
                <div id="ae_contents_box_100pc">
                    <div id="ae_content">
                        <div id="ae_navi">
                            <a href="${interface.application.link.www_domain}/">EBI</a>
                            <xsl:text> > </xsl:text>
                            <a href="{$basepath}">ArrayExpress</a>
                            <xsl:text> > </xsl:text>
                            <a href="{$basepath}/experiments">Experiments</a>
                            <xsl:text> > </xsl:text>
                            <a href="{$basepath}/experiments/{fn:upper-case($accession)}">
                                <xsl:value-of select="fn:upper-case($accession)"/>
                            </a>
                            <xsl:text> > </xsl:text>
                            <a href="{$basepath}/experiments/{fn:upper-case($accession)}/sdrf">
                                <xsl:text>Sample and Data Relationship</xsl:text>
                            </a>
                        </div>
                        <div id="ae_summary_box">
                            <div id="ae_accession">
                                <a href="{$basepath}/experiments/{$vAccession}">
                                    <xsl:text>Experiment </xsl:text>
                                    <xsl:value-of select="$vAccession"/>
                                </a>
                                <xsl:if test="not($vMetaData/user/@id = '1')">
                                    <img src="{$basepath}/assets/images/silk_lock.gif" alt="Access to the data is restricted" width="8" height="9"/>
                                </xsl:if>
                            </div>
                            <div id="ae_title">
                                <div>
                                    <xsl:value-of select="$vMetaData/name"/>
                                    <xsl:if test="$vMetaData/samples">
                                        <xsl:text> (</xsl:text>
                                        <xsl:value-of select="$vMetaData/samples"/>
                                        <xsl:text> samples)</xsl:text>
                                    </xsl:if>
                                </div>
                            </div>
                        </div>
                        <div id="ae_results_box">
                            <xsl:apply-templates select="/table"/>
                        </div>
                    </div>
                </div>
            </xsl:when>
            <xsl:when test="fn:exists($vHeader) and not(fn:exists($vMetaData))">
                <xsl:call-template name="block-access-restricted"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="block-not-found"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="table">
        <table id="ae_results_table" border="0" cellpadding="0" cellspacing="0">
            <xsl:apply-templates select="row"/>
        </table>
    </xsl:template>

    <xsl:template match="row">
        <xsl:if test="col > ''">
            <xsl:variable name="vIsHeader" select="(. = $vHeader)"/>
            <tr>
                <xsl:for-each select="col">
                    <xsl:variable name="vColNum" select="fn:position()"/>
                    <xsl:variable name="vIsColComplex" select="fn:matches($vHeader/col[$vColNum], '.+\[.+\].*')"/>
                    <xsl:variable name="vColType" select="if ($vIsColComplex) then fn:replace($vHeader/col[$vColNum], '(.+[^\s])\s*\[.+\].*', '$1') else $vHeader/col[$vColNum]"/>
                    <xsl:variable name="vColName" select="if ($vIsColComplex) then fn:replace($vHeader/col[$vColNum], '.+\[(.+)\].*', '$1') else $vHeader/col[$vColNum]"/>
                    <xsl:choose>
                        <xsl:when test="($vColType = 'Comment' and (fn:index-of($vPermittedComment, lower-case($vColName)))) or (fn:index-of($vPermittedColType, lower-case($vColType)))">
                            <xsl:choose>
                                <xsl:when test="$vIsHeader">
                                    <th class="col_{$vColNum}">
                                        <xsl:if test="not($vColType = 'Unit' or $vColName = 'TimeUnit')">
                                            <xsl:value-of select="$vColName"/>
                                        </xsl:if>
                                        <xsl:if test="$vColType = 'Unit' or $vColName = 'TimeUnit'">
                                            <xsl:text>(unit)</xsl:text>
                                        </xsl:if>
                                    </th>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:choose>
                                        <xsl:when test="fn:contains(fn:lower-case($vColType),'file')">
                                            <td class="col_{$vColNum}">
                                                <xsl:choose>
                                                    <xsl:when test="fn:position() != fn:last() and (text()) and fn:matches(following-sibling::col[1]/text(), '^ftp://.+')">
                                                        <a href="{fn:replace(following-sibling::col[1]/text(), '^.+/experiment/[^/]+/', fn:concat($basepath, '/files/'))}/{fn:encode-for-uri(text())}">
                                                            <xsl:value-of select="text()"/>
                                                        </a>
                                                    </xsl:when>
                                                    <xsl:otherwise>
                                                        <xsl:value-of select="text()"/>
                                                        <xsl:if test="not(text())">
                                                            <xsl:text>&#160;</xsl:text>
                                                        </xsl:if>
                                                    </xsl:otherwise>
                                                </xsl:choose>
                                            </td>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <td class="col_{$vColNum}"><commit_msg>- if no archive url is in comment but we have ONE archive in files directory, use it (obviously could have a false positive here)<commit_after><?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fn="http://www.w3.org/2005/xpath-functions"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:ae="http://www.ebi.ac.uk/arrayexpress/XSLT/Extension"
                xmlns:aejava="java:uk.ac.ebi.arrayexpress.utils.saxon.ExtFunctions"
                xmlns:search="java:uk.ac.ebi.arrayexpress.utils.saxon.search.SearchExtension"
                xmlns:html="http://www.w3.org/1999/xhtml"
                extension-element-prefixes="ae aejava search html fn xs"
                exclude-result-prefixes="ae aejava search html fn xs"
                version="2.0">

    <xsl:param name="accession"/>
    <xsl:param name="filename"/>

    <xsl:param name="host"/>
    <xsl:param name="basepath"/>
    <xsl:param name="userid"/>

    <xsl:variable name="vBaseUrl">http://<xsl:value-of select="$host"/><xsl:value-of select="$basepath"/></xsl:variable>

    <xsl:variable name="vPermittedColType" select="fn:tokenize('source name,characteristics,unit,factorvalue,factor value,array data file,derived array data file,array data matrix file,derived array data matrix file', '\s*,\s*')"/>
    <xsl:variable name="vPermittedComment" select="fn:tokenize('sample_description,sample_source_name', '\s*,\s*')"/>
    <xsl:variable name="vHeader" select="/table/row[col[1] = 'Source Name'][1]"/>
    <xsl:variable name="vAccession" select="fn:upper-case($accession)"/>
    <xsl:variable name="vMetaData" select="search:queryIndex('experiments', fn:concat('visible:true accession:', $accession, if ($userid) then fn:concat(' userid:(', $userid, ')') else ''))[accession = $vAccession]" />
    <xsl:variable name="vDataFolder" select="aejava:getAcceleratorValueAsSequence('ftp-folder', $vAccession)"/>

    <xsl:output omit-xml-declaration="yes" method="html"
                indent="no" encoding="ISO-8859-1" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>

    <xsl:include href="ae-html-page.xsl"/>

    <xsl:template match="/">
        <html lang="en">
            <xsl:call-template name="page-header">
                <xsl:with-param name="pTitle">SDRF | <xsl:value-of select="$vAccession"/> | Experiments | ArrayExpress Archive | EBI</xsl:with-param>
                <xsl:with-param name="pExtraCode">
                    <link rel="stylesheet" href="{$basepath}/assets/stylesheets/ae_sdrf_view_20.css" type="text/css"/>
                    <script src="{$basepath}/assets/scripts/jquery-1.4.2.min.js" type="text/javascript"/>
                    <script src="{$basepath}/assets/scripts/jquery.cookie-1.0.js" type="text/javascript"/>
                    <script src="{$basepath}/assets/scripts/ae_common_20.js" type="text/javascript"/>
                    <script src="{$basepath}/assets/scripts/ae_sdrf_view_20.js" type="text/javascript"/>
                </xsl:with-param>
            </xsl:call-template>
            <xsl:call-template name="page-body"/>
        </html>
    </xsl:template>

    <xsl:template name="ae-contents">
        <xsl:choose>
            <xsl:when test="exists($vHeader) and exists($vMetaData)">
                <div id="ae_contents_box_100pc">
                    <div id="ae_content">
                        <div id="ae_navi">
                            <a href="${interface.application.link.www_domain}/">EBI</a>
                            <xsl:text> > </xsl:text>
                            <a href="{$basepath}">ArrayExpress</a>
                            <xsl:text> > </xsl:text>
                            <a href="{$basepath}/experiments">Experiments</a>
                            <xsl:text> > </xsl:text>
                            <a href="{$basepath}/experiments/{fn:upper-case($accession)}">
                                <xsl:value-of select="fn:upper-case($accession)"/>
                            </a>
                            <xsl:text> > </xsl:text>
                            <a href="{$basepath}/experiments/{fn:upper-case($accession)}/sdrf">
                                <xsl:text>Sample and Data Relationship</xsl:text>
                            </a>
                        </div>
                        <div id="ae_summary_box">
                            <div id="ae_accession">
                                <a href="{$basepath}/experiments/{$vAccession}">
                                    <xsl:text>Experiment </xsl:text>
                                    <xsl:value-of select="$vAccession"/>
                                </a>
                                <xsl:if test="not($vMetaData/user/@id = '1')">
                                    <img src="{$basepath}/assets/images/silk_lock.gif" alt="Access to the data is restricted" width="8" height="9"/>
                                </xsl:if>
                            </div>
                            <div id="ae_title">
                                <div>
                                    <xsl:value-of select="$vMetaData/name"/>
                                    <xsl:if test="$vMetaData/samples">
                                        <xsl:text> (</xsl:text>
                                        <xsl:value-of select="$vMetaData/samples"/>
                                        <xsl:text> samples)</xsl:text>
                                    </xsl:if>
                                </div>
                            </div>
                        </div>
                        <div id="ae_results_box">
                            <xsl:apply-templates select="/table"/>
                        </div>
                    </div>
                </div>
            </xsl:when>
            <xsl:when test="fn:exists($vHeader) and not(fn:exists($vMetaData))">
                <xsl:call-template name="block-access-restricted"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="block-not-found"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="table">
        <table id="ae_results_table" border="0" cellpadding="0" cellspacing="0">
            <xsl:apply-templates select="row"/>
        </table>
    </xsl:template>

    <xsl:template match="row">
        <xsl:if test="col > ''">
            <xsl:variable name="vIsHeader" select="(. = $vHeader)"/>
            <tr>
                <xsl:for-each select="col">
                    <xsl:variable name="vColNum" select="fn:position()"/>
                    <xsl:variable name="vIsColComplex" select="fn:matches($vHeader/col[$vColNum], '.+\[.+\].*')"/>
                    <xsl:variable name="vColType" select="if ($vIsColComplex) then fn:replace($vHeader/col[$vColNum], '(.+[^\s])\s*\[.+\].*', '$1') else $vHeader/col[$vColNum]"/>
                    <xsl:variable name="vColName" select="if ($vIsColComplex) then fn:replace($vHeader/col[$vColNum], '.+\[(.+)\].*', '$1') else $vHeader/col[$vColNum]"/>
                    <xsl:choose>
                        <xsl:when test="($vColType = 'Comment' and (fn:index-of($vPermittedComment, lower-case($vColName)))) or (fn:index-of($vPermittedColType, lower-case($vColType)))">
                            <xsl:choose>
                                <xsl:when test="$vIsHeader">
                                    <th class="col_{$vColNum}">
                                        <xsl:if test="not($vColType = 'Unit' or $vColName = 'TimeUnit')">
                                            <xsl:value-of select="$vColName"/>
                                        </xsl:if>
                                        <xsl:if test="$vColType = 'Unit' or $vColName = 'TimeUnit'">
                                            <xsl:text>(unit)</xsl:text>
                                        </xsl:if>
                                    </th>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:choose>
                                        <xsl:when test="fn:contains(fn:lower-case($vColType),'file')">
                                            <xsl:variable name="vDataKind" select="if (fn:contains(fn:lower-case($vColType),'derived')) then 'fgem' else 'raw'"/>
                                            <xsl:variable name="vAvailArchives" select="$vDataFolder/file[@extension = 'zip' and @kind = $vDataKind]/@name"/>
                                            <xsl:variable name="vArchive" select="fn:replace(following-sibling::col[1]/text(), '^.+([^/]+)$', '$1')"/>
                                            <td class="col_{$vColNum}">
                                                <xsl:choose>
                                                    <xsl:when test="(text()) and (fn:index-of($vAvailArchives, $vArchive))">
                                                        <a href="{$basepath}/files/{$vAccession}/{$vArchive}/{fn:encode-for-uri(text())}">
                                                            <xsl:value-of select="text()"/>
                                                        </a>
                                                    </xsl:when>
                                                    <xsl:when test="(text()) and count($vAvailArchives) = 1">
                                                        <a href="{$basepath}/files/{$vAccession}/{$vAvailArchives}/{fn:encode-for-uri(text())}">
                                                            <xsl:value-of select="text()"/>
                                                        </a>
                                                    </xsl:when>
                                                    <xsl:otherwise>
                                                        <xsl:value-of select="text()"/>
                                                        <xsl:if test="not(text())">
                                                            <xsl:text>&#160;</xsl:text>
                                                        </xsl:if>
                                                    </xsl:otherwise>
                                                </xsl:choose>
                                            </td>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <td class="col_{$vColNum}">
{'fraction_non_alphanumeric': 0.15351205631271528, 'fraction_numerical': 0.006340172732264989, 'mean_word_length': 1.2870190661034364, 'pattern_counts': {'":': 0, '<': 314, '<?xml version=': 2, '>': 324, 'https://': 0, 'lorem ipsum': 0, 'www.': 12, 'xml': 18}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 130, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3230773', 'n_tokens_mistral': 5509, 'n_tokens_neox': 5021, 'n_words': 761}