<commit_before><?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <xsl:output method="xml"/>

  <xsl:variable name="docname">
    <xsl:value-of select="substring-before(/ead/eadheader/eadid, '.xml')"/>
  </xsl:variable>

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

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()|processing-instruction()|comment()"/>
    </xsl:copy>
  </xsl:template>


  <xsl:template match="c01[@level='series'] | c02[@level='subseries'] | c03[@level='subseries']">
    <xsl:variable name="seriesid">
      <xsl:apply-templates select="did/unitid" mode="id"/>
    </xsl:variable>

    <!-- add a human-readable id based on the unitid (e.g., series # or subseries #.#) -->

    <xsl:copy>
      <xsl:attribute name="id">
        <xsl:value-of select="concat($docname, '_', $seriesid)"/>
      </xsl:attribute>

      <xsl:apply-templates select="@*|node()|processing-instruction()|comment()"/>
    </xsl:copy>
  </xsl:template>

  <!-- ignore any existing ids : they should be replaced  -->
  <xsl:template match="c01[@level='series']/@id | c02[@level='subseries']/@id | 
                       c03[@level='subseries']/@id"/>


  <!-- strings for translating case -->
  <xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>
  <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>


  <!-- convert unitid into a usable format for id and url -->
  <xsl:template match="unitid" mode="id">

    <xsl:variable name="space" select="' '"/>
    <xsl:variable name="nospace" select="''"/>

    <!-- if the unitid ends with a period, remove it (for clean urls) -->
    <xsl:variable name="id1">
      <xsl:choose>
        <xsl:when test="substring(., string-length(.), 1) = '.'">
          <xsl:value-of select="substring(., 1, string-length(.) - 1)"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="."/>
       </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <!-- remove spaces -->
    <xsl:value-of select="translate($id1, $space, $nospace)"/>

    <!-- note: not translating to lower-case because it makes roman numerals look strange -->
    <!--    <xsl:value-of select="translate(translate($id1, $space, $nospace), $uppercase, $lowercase)"/> -->
  </xsl:template>

</xsl:stylesheet>
<commit_msg>revert to lower-casing series ids<commit_after><?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <xsl:output method="xml"/>

  <xsl:variable name="docname">
    <xsl:value-of select="substring-before(/ead/eadheader/eadid, '.xml')"/>
  </xsl:variable>

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

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()|processing-instruction()|comment()"/>
    </xsl:copy>
  </xsl:template>


  <xsl:template match="c01[@level='series'] | c02[@level='subseries'] | c03[@level='subseries']">
    <xsl:variable name="seriesid">
      <xsl:apply-templates select="did/unitid" mode="id"/>
    </xsl:variable>

    <!-- add a human-readable id based on the unitid (e.g., series # or subseries #.#) -->

    <xsl:copy>
      <xsl:attribute name="id">
        <xsl:value-of select="concat($docname, '_', $seriesid)"/>
      </xsl:attribute>

      <xsl:apply-templates select="@*|node()|processing-instruction()|comment()"/>
    </xsl:copy>
  </xsl:template>

  <!-- ignore any existing ids : they should be replaced  -->
  <xsl:template match="c01[@level='series']/@id | c02[@level='subseries']/@id | 
                       c03[@level='subseries']/@id"/>


  <!-- strings for translating case -->
  <xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>
  <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>


  <!-- convert unitid into a usable format for id and url -->
  <xsl:template match="unitid" mode="id">

    <xsl:variable name="space" select="' '"/>
    <xsl:variable name="nospace" select="''"/>

    <!-- if the unitid ends with a period, remove it (for clean urls) -->
    <xsl:variable name="id1">
      <xsl:choose>
        <xsl:when test="substring(., string-length(.), 1) = '.'">
          <xsl:value-of select="substring(., 1, string-length(.) - 1)"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="."/>
       </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <!-- remove spaces -->
    <!--    <xsl:value-of select="translate($id1, $space, $nospace)"/>-->

    <!-- note: translating to lower-case makes roman numerals look strange..  -->
    <xsl:value-of select="translate(translate($id1, $space, $nospace), $uppercase, $lowercase)"/> 
  </xsl:template>

</xsl:stylesheet>

{'fraction_non_alphanumeric': 0.20933550754178556, 'fraction_numerical': 0.01141459437423563, 'mean_word_length': 3.3348056537102475, 'pattern_counts': {'":': 0, '<': 109, '<?xml version=': 2, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7529665', 'n_tokens_mistral': 1781, 'n_tokens_neox': 1577, 'n_words': 313}